/**
  * Add default categories to the project
  *
  * @access public
  * @param void
  * @return null
  */
 function add_default_categories()
 {
     if (!ProjectCategory::canAdd(logged_user(), active_project())) {
         flash_error(lang('no access permissions'));
         $this->redirectToReferer(get_url('tickets', 'categories'));
     }
     // if
     $default_categories_config = str_replace(array("\r\n", "\r"), array("\n", "\n"), config_option('tickets_default_categories', ''));
     if (trim($default_categories_config) == '') {
         $default_categories = array();
     } else {
         $default_categories = explode("\n", $default_categories_config);
     }
     // if
     if (count($default_categories)) {
         $category_names = '';
         $added_categories = array();
         $categories = ProjectCategories::getProjectCategories(active_project());
         foreach ($categories as $category) {
             $added_categories[] = $category->getName();
         }
         try {
             DB::beginWork();
             foreach ($default_categories as $default_category) {
                 $category_name = trim($default_category);
                 if ($category_name == '') {
                     continue;
                 }
                 // if
                 if (in_array($category_name, $added_categories)) {
                     continue;
                 }
                 // if
                 $category = new ProjectCategory();
                 $category->setProjectId(active_project()->getId());
                 $category->setName($category_name);
                 $category->save();
                 ApplicationLogs::createLog($category, active_project(), ApplicationLogs::ACTION_ADD);
                 $category_names .= $category_name . ', ';
                 $added_categories[] = $category_name;
             }
             // foreach
             DB::commit();
             // Error...
         } catch (Exception $e) {
             DB::rollback();
             tpl_assign('error', $e);
         }
         // try
     }
     // if
     flash_success(lang('success add category', $category_names));
     $this->redirectTo('tickets', 'categories');
 }
Exemplo n.º 2
0
<?php

// Set page title and set crumbs to index
set_page_title(lang('ticket categories'));
project_tabbed_navigation(PROJECT_TAB_TICKETS);
project_crumbs(array(array(lang('tickets'), get_url('tickets')), array(lang('ticket categories'))));
if (ProjectCategory::canAdd(logged_user(), active_project())) {
    add_page_action(lang('add ticket category'), get_url('tickets', 'add_category'));
    add_page_action(lang('add default ticket categories'), get_url('tickets', 'add_default_categories'));
}
add_stylesheet_to_page('tickets/tickets.css');
if (isset($categories) && is_array($categories) && count($categories)) {
    ?>
<div id="listing">
<table width="100%" cellpadding="2" border="0">
  <tr>
    <th>Category</th>
    <th>Description</th>
  </tr>
  <?php 
    foreach ($categories as $category) {
        ?>
    <tr>
      <td><a href="<?php 
        echo $category->getViewUrl();
        ?>
"><?php 
        echo $category->getName();
        ?>
</a></td>
      <td><?php