/**
  * Export project milestones
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $active_milestones = array();
     $completed_milestones = array();
     $all_milestones = Milestones::findAllByProject($this->active_project, $object_visibility);
     if (is_foreachable($all_milestones)) {
         $output_builder->setFileTemplate(MILESTONES_MODULE, 'milestones', 'object');
         foreach ($all_milestones as $milestone) {
             if ($milestone->isCompleted()) {
                 $completed_milestones[] = $milestone;
             } else {
                 $active_milestones[] = $milestone;
             }
             // if
             // Build milestone details page
             $objects = array();
             event_trigger('on_milestone_objects_by_visibility', array(&$milestone, &$objects, $object_visibility));
             $total_objects = 0;
             if (is_foreachable($objects)) {
                 foreach ($objects as $objects_per_module) {
                     $total_objects += count($objects_per_module);
                 }
                 // foreach
             }
             // if
             $output_builder->smarty->assign(array('active_milestone' => $milestone, 'active_milestone_objects' => $objects, 'total_objects' => $total_objects));
             $output_builder->outputToFile('milestone_' . $milestone->getId());
         }
         // foreach
     }
     // if
     // export milestones front page
     $output_builder->setFileTemplate(MILESTONES_MODULE, 'milestones', 'index');
     $output_builder->smarty->assign('active_milestones', $active_milestones);
     $output_builder->smarty->assign('completed_milestones', $completed_milestones);
     $output_builder->outputToFile('index');
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Export files
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $module_categories = Categories::findByModuleSection($this->active_project, $this->active_module, $this->active_module);
     $module_objects = Files::findByProject($this->active_project, STATE_VISIBLE, $object_visibility);
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->smarty->assign('categories', $module_categories);
     $output_builder->smarty->assign('objects', $module_objects);
     $output_builder->outputToFile('index');
     // export files by categories
     if (is_foreachable($module_categories)) {
         foreach ($module_categories as $module_category) {
             if (instance_of($module_category, 'Category')) {
                 $objects = Files::find(array('conditions' => array('parent_id = ? AND project_id = ? AND type = ? AND state >= ? AND visibility >= ?', $module_category->getId(), $this->active_project->getId(), 'File', STATE_VISIBLE, $object_visibility), 'order' => 'boolean_field_1, datetime_field_1 DESC'));
                 $output_builder->smarty->assign(array('current_category' => $module_category, 'objects' => $objects));
                 $output_builder->outputToFile('category_' . $module_category->getId());
             }
             // if
         }
         // foreach
     }
     // if
     // export files
     if (is_foreachable($module_objects)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($module_objects as $module_object) {
             if (instance_of($module_object, 'File')) {
                 $revisions = $module_object->getRevisions();
                 $output_builder->outputAttachments($revisions);
                 $comments = $module_object->getComments($object_visibility);
                 $output_builder->outputObjectsAttachments($comments);
                 $output_builder->smarty->assign('object', $module_object);
                 $output_builder->smarty->assign('comments', $comments);
                 $output_builder->outputToFile('file_' . $module_object->getId());
             }
             // if
         }
         // foreach
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Exports basic project info
  * 
  * @param void
  * @return void
  */
 function export()
 {
     if ($this->active_project->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, false, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $output_builder->setFileTemplate(SYSTEM_MODULE, 'project', 'index');
     $output_builder->outputToFile('index');
     $output_builder->outputProjectIcon();
     $output_builder->outputStyle();
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Exports time records
  * 
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $timerecords = TimeRecords::findByProject($this->active_project, STATE_VISIBLE, $object_visibility);
     $distinct_months = array();
     foreach ($timerecords as $timerecord) {
         $date = $timerecord->getRecordDate();
         $exists = false;
         for ($x = 0; $x < count($distinct_months); $x++) {
             if ($distinct_months[$x]['month'] == $date->getMonth() && $distinct_months[$x]['year'] == $date->getYear()) {
                 $exists = true;
             }
             // if
         }
         // for
         if (!$exists) {
             $distinct_months[] = array("year" => $date->getYear(), "month" => $date->getMonth(), "month_string" => $date->date_data['month'], "beginning_of_month" => DateTimeValue::beginningOfMonth($date->getMonth(), $date->getYear()), "end_of_month" => DateTimeValue::endOfMonth($date->getMonth(), $date->getYear()));
         }
         // if
     }
     // foreach
     $people = ProjectUsers::findUsersByProject($this->active_project);
     $companies = Companies::findByProject($this->active_project);
     $total_times = array();
     foreach ($people as $person) {
         $person->temp_total_time = TimeRecords::getTotalUserTimeOnProject($this->active_project, $person);
     }
     // foreach
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->smarty->assign(array("distinct_months" => $distinct_months, "people" => $people, "companies" => $companies, "total_times" => $total_times, "timerecords" => $timerecords));
     $output_builder->outputToFile('index');
     // export monthly report
     if (is_foreachable($distinct_months)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'monthly');
         foreach ($distinct_months as $distinct_month) {
             $output_builder->smarty->assign(array('current_month' => $distinct_month, 'start_date' => DateTimeValue::beginningOfMonth($distinct_month[month], $distinct_month['year']), 'end_date' => DateTimeValue::endOfMonth($distinct_month['month'], $distinct_month['year'])));
             $output_builder->outputToFile('monthly_' . $distinct_month['month'] . '_' . $distinct_month['year']);
         }
         // foreach
     }
     // if
     // export report for persons
     if (is_foreachable($people)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'person');
         foreach ($people as $person) {
             $output_builder->smarty->assign(array('current_person' => $person));
             $output_builder->outputToFile('user_' . $person->getId());
         }
         // foreach
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Export project pages
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $module_categories = Categories::findByModuleSection($this->active_project, PAGES_MODULE, 'pages');
     $output_builder->smarty->assign(array('categories' => $module_categories, 'visibility' => $object_visibility));
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->outputToFile('index');
     if (is_foreachable($module_categories)) {
         foreach ($module_categories as $module_category) {
             $output_builder->smarty->assign('current_category', $module_category);
             $output_builder->smarty->assign('objects', Pages::findByCategory($module_category, STATE_VISIBLE, $object_visibility));
             $output_builder->outputToFile('category_' . $module_category->getId());
         }
         // foreach
     }
     // if
     $pages = ProjectObjects::find(array("conditions" => array("project_id = ? AND module = ? AND type = ?", $this->active_project->getId(), 'pages', 'Page')));
     $page_ids = array();
     if (is_foreachable($pages)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($pages as $page) {
             if (instance_of($page, 'Page')) {
                 $page_ids[] = $page->getId();
                 $parent = $page->getParent();
                 $comments = $page->getComments($object_visibility);
                 $output_builder->smarty->assign(array('page' => $page, 'subpages' => $page->getSubpages($object_visibility), 'parent' => $parent, 'comments' => $comments));
                 if (instance_of($parent, 'Page')) {
                     $output_builder->smarty->assign('parent_url', './page_' . $parent->getId() . '.html');
                 } else {
                     if (instance_of($parent, 'Category')) {
                         $output_builder->smarty->assign('parent_url', './category_' . $parent->getId() . '.html');
                     }
                 }
                 // if
                 $output_builder->outputToFile('page_' . $page->getId());
                 $output_builder->outputObjectsAttachments($comments);
                 $output_builder->outputAttachments($page->getAttachments());
             }
             // if
         }
         // foreach
         $revisions = PageVersions::findByPageIds($page_ids);
         if (is_foreachable($revisions)) {
             $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'revision');
             foreach ($revisions as $revision) {
                 $output_builder->smarty->assign('revision', $revision);
                 $output_builder->outputToFile('revision_' . $revision->getPageId() . '_' . $revision->getVersion());
             }
             // foreach
         }
         // if
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Download exported data
  * 
  * @param void
  * @return null
  */
 function download()
 {
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, null);
     $filename = $output_builder->getOutputArchivePath();
     if (!is_file($filename)) {
         $this->httpError(HTTP_NOT_FOUND);
     }
     // if
     download_file($filename, 'application/zip', basename($filename), true);
 }
 /**
  * Export project checklists
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $completed_checklists = Checklists::findCompletedByProject($this->active_project, STATE_VISIBLE, $object_visibility);
     $active_checklists = Checklists::findActiveByProject($this->active_project, STATE_VISIBLE, $object_visibility);
     $checklists = array_merge((array) $completed_checklists, (array) $active_checklists);
     // export checklists front page
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->smarty->assign('active_objects', $active_checklists);
     $output_builder->smarty->assign('completed_objects', $completed_checklists);
     $output_builder->outputToFile('index');
     if (is_foreachable($checklists)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($checklists as $checklist) {
             if (instance_of($checklist, 'Checklist')) {
                 $output_builder->smarty->assign(array('object' => $checklist));
                 $output_builder->outputToFile('checklist_' . $checklist->getId());
             }
             // if
         }
         // foreach
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Export tickets
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $module_categories = Categories::findByModuleSection($this->active_project, $this->active_module, $this->active_module);
     $module_objects = Tickets::findByProject($this->active_project, null, STATE_VISIBLE, $object_visibility);
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->smarty->assign('categories', $module_categories);
     $output_builder->smarty->assign('objects', $module_objects);
     $output_builder->outputToFile('index');
     // export tickets by categories
     if (is_foreachable($module_categories)) {
         foreach ($module_categories as $module_category) {
             if (instance_of($module_category, 'Category')) {
                 $output_builder->smarty->assign(array('current_category' => $module_category, 'objects' => Tickets::findByProject($this->active_project, $module_category, STATE_VISIBLE, $object_visibility)));
                 $output_builder->outputToFile('category_' . $module_category->getId());
             }
             // if
         }
         // foreach
     }
     // if
     // export tickets
     if (is_foreachable($module_objects)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($module_objects as $module_object) {
             if (instance_of($module_object, 'Ticket')) {
                 $output_builder->outputAttachments($module_object->getAttachments());
                 $comments = $module_object->getComments($object_visibility);
                 $output_builder->outputObjectsAttachments($comments);
                 if (module_loaded('timetracking')) {
                     $timerecords = TimeRecords::findByParent($module_object, null, STATE_VISIBLE, $object_visibility);
                     $total_time = TimeRecords::calculateTime($timerecords);
                 } else {
                     $timerecords = null;
                     $total_time = 0;
                 }
                 // if
                 $output_builder->smarty->assign(array('timerecords' => $timerecords, 'total_time' => $total_time, 'object' => $module_object, 'comments' => $comments));
                 $output_builder->outputToFile('ticket_' . $module_object->getId());
             }
             // if
         }
         // foreach
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }