Browse Source

Addin new features;

New settings: warn_admin_no_user_in_category, send_warning_to_all_admins, WarningCategoryXDoesntHaveUsers,
allow_category_edition  and relate users to categories
Julio 9 years ago
parent
commit
a46bf3aa8e

+ 5 - 1
plugin/ticket/lang/english.php

@@ -85,6 +85,10 @@ $strings['PleaseBeforeRegisterATicketSelectOneUser'] = "Please select a user bef
 $strings['RequestConfirmation'] = "Request confirmation";
 $strings['TicketUpdated'] = "Ticket updated";
 $strings['TicketClosed'] = "Ticket closed";
-
 $strings['allow_category_edition'] = "Allow category edition";
+$strings['warn_admin_no_user_in_category'] = "Warn admin if category doesn't have users related";
+$strings['send_warning_to_all_admins'] = "Send warning to all admins, if category doesn't have users related";
+$strings['WarningCategoryXDoesntHaveUsers'] = "Warning: The category '%s' doesn't have users assigned";
+$strings['TicketInformation'] = 'Ticket information';
+
 

+ 0 - 1
plugin/ticket/src/categories.php

@@ -104,7 +104,6 @@ function modify_filter($id, $params, $row)
 	return $result;
 }
 
-
 Display::display_header($plugin->get_lang('MyTickets'));
 $table->set_header(0, '', false);
 $table->set_header(1, $plugin->get_lang('Title'), true);

+ 3 - 4
plugin/ticket/src/categories_add_user.php

@@ -5,7 +5,7 @@
  *
  * @package chamilo.plugin.ticket
  */
-
+$cidReset = true;
 require_once '../config.php';
 $plugin = TicketPlugin::create();
 
@@ -17,10 +17,7 @@ if (empty($categoryId)) {
 }
 
 $form = new FormValidator('edit', 'post', api_get_self().'?id='.$categoryId);
-
-
 $users = UserManager::get_user_list([], ['firstname']);
-
 $users = array_column($users, 'complete_name', 'user_id');
 
 $form->addElement(
@@ -48,5 +45,7 @@ if ($form->validate()) {
     header("Location: ".api_get_self()."?id=".$categoryId);
     exit;
 }
+
+$interbreadcrumb[] = array('url' => 'categories.php', 'name' => get_lang('Categories'));
 Display::display_header();
 $form->display();

+ 0 - 1
plugin/ticket/src/course_user_list.php

@@ -31,7 +31,6 @@ $userInput = Display::tag(
     )
 );
 $userControl = Display::div($userInput, array('class' => 'controls'));
-
 $courseLabel = Display::tag('label', get_lang('Course'), array('class' => 'control-label'));
 $courseSelect = Display::select('course_id', $arrCourseList, 0, array(), false);
 $courseControl = Display::div($courseSelect, array('class' => 'controls'));

+ 2 - 2
plugin/ticket/src/myticket.php

@@ -298,8 +298,8 @@ if ($isAdmin) {
 
         if ($plugin->get('allow_category_edition')) {
             echo Display::url(
-                    Display::return_icon('document.png'),
-                    api_get_path(WEB_PLUGIN_PATH) . 'ticket/src/categories.php'
+                Display::return_icon('folder_document.gif'),
+                api_get_path(WEB_PLUGIN_PATH) . 'ticket/src/categories.php'
             );
         }
 

+ 10 - 14
plugin/ticket/src/new_ticket.php

@@ -132,7 +132,7 @@ function add_image_form() {
     });
 
     img_remove = $("<img/>", {
-        src: "' . api_get_path(WEB_CODE_PATH) . 'img/delete.gif"
+        src: "' . Display::returnIconPath('delete.png') . '"
     });
 
     new_filepath_id = $("#filepath_" + counter_image);
@@ -317,8 +317,7 @@ function show_form_send_ticket()
         )
     );
 
-    $form->addElement(
-        'html',
+    $form->addLabel('',
         Display::div(
             '',
             array(
@@ -394,18 +393,15 @@ function show_form_send_ticket()
             'for' => 'priority_id'
         )
     );
-
-    $form->addElement('html', '<span id="filepaths">');
-    $form->addElement('html', '<div id="filepath_1">');
     $form->addElement('file', 'attach_1', get_lang('FilesAttachment'));
-    $form->addElement('html', '</div>');
-    $form->addElement('html', '</span>');
+     $form->addLabel('', '<span id="filepaths"><div id="filepath_1"></div></span>');
 
-    $form->addElement('html', '<div class="controls">');
-    $form->addElement('html', '<span id="link-more-attach" >');
-    $form->addElement('html', '<span class="label label-info" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</span>');
-    $form->addElement('html', '</span>');
-    $form->addElement('html', '(' . sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))) . ')');
+    $form->addLabel('',
+        '<span id="link-more-attach">
+         <span class="btn btn-success" onclick="return add_image_form()">' . get_lang('AddOneMoreFile') . '</span>
+         </span>
+         ('.sprintf(get_lang('MaximunFileSizeX'), format_file_size(api_get_setting('message_max_upload_filesize'))).')
+    ');
 
     $form->addElement('html', '<br/>');
     $form->addElement(
@@ -415,7 +411,7 @@ function show_form_send_ticket()
         null,
         null,
         null,
-        'save',
+        'btn btn-primary',
         array(
             'id' => 'btnsubmit'
         )

+ 89 - 33
plugin/ticket/src/ticket.class.php

@@ -152,6 +152,8 @@ class TicketManager
     /**
      * @param int $userId
      * @param int $categoryId
+     *
+     * @return bool
      */
     public static function userIsAssignedToCategory($userId, $categoryId)
     {
@@ -166,6 +168,8 @@ class TicketManager
 
     /**
      * @param int $categoryId
+     *
+     * @return array
      */
     public static function getUsersInCategory($categoryId)
     {
@@ -272,7 +276,8 @@ class TicketManager
         if ($request_user == '' && $source == 'VRT') {
             $request_user = $user_id;
         }
-        $sql_insert_ticket = "INSERT INTO $table_support_tickets
+        // insert_ticket
+        $sql = "INSERT INTO $table_support_tickets
             (
             project_id,
             category_id,
@@ -302,7 +307,7 @@ class TicketManager
             '$now',
             '$source'
         )";
-        Database::query($sql_insert_ticket);
+        Database::query($sql);
         $ticket_id = Database::insert_id();
 
         if ($assigned_user != 0) {
@@ -313,41 +318,54 @@ class TicketManager
             $ticket_code = "A" . str_pad(
                 (int) $ticket_id, 11, "0", STR_PAD_LEFT
             );
-            $sql_update_code = "UPDATE $table_support_tickets
-                                SET ticket_code = '$ticket_code'
-                                WHERE ticket_id = '$ticket_id'";
-            Database::query($sql_update_code);
+            // Update code
+            $sql = "UPDATE $table_support_tickets
+                    SET ticket_code = '$ticket_code'
+                    WHERE ticket_id = '$ticket_id'";
+            Database::query($sql);
             $data_files = array();
-            $sql_update_total = "UPDATE $table_support_category
-                                 SET total_tickets = total_tickets +1
-                                 WHERE category_id = '$category_id';";
-            Database::query($sql_update_total);
+            // Update total
+            $sql = "UPDATE $table_support_category
+                     SET total_tickets = total_tickets +1
+                     WHERE category_id = '$category_id';";
+            Database::query($sql);
             if (self::insert_message($ticket_id, $subject, $content, $file_attachments, $request_user)) {
+
+                $user = api_get_user_info($request_user);
+                $helpDeskMessage =
+                    '<table>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('User') . '</b></td>
+                                <td width="400px">' . $user['firstname']. ' ' . $user['lastname'] . '</td>
+                            </tr>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('Username') . '</b></td>
+                                <td width="400px">' . $user['username'] . '</td>
+                            </tr>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('Email') . '</b></td>
+                                <td width="400px">' . $user['email'] . '</td>
+                            </tr>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('Phone') . '</b></td>
+                                <td width="400px">' . $user['phone'] . '</td>
+                            </tr>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('Date') . '</b></td>
+                                <td width="400px">' . api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG) . '</td>
+                            </tr>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('Topic') . '</b></td>
+                                <td width="400px">' . $subject . '</td>
+                            </tr>
+                            <tr>
+                                <td width="100px"><b>' . get_lang('Description') . '</b></td>
+                                <td width="400px">' . $content . '</td>
+                            </tr>
+                        </table>';
+
                 global $data_files;
                 if ($other_area) {
-                    $user = api_get_user_info($request_user);
-                    $helpDeskMessage = '<table>
-                                            <tr>
-                                                <td width="100px"><b>' . get_lang('User') . '</b></td>
-                                                <td width="400px">' . $user['firstname']. ' ' . $user['lastname'] . '</td>
-                                            </tr>
-                                            <tr>
-                                                <td width="100px"><b>' . get_lang('Username') . '</b></td>
-                                                <td width="400px">' . $user['username'] . '</td>
-                                            </tr>
-                                            <tr>
-                                                <td width="100px"><b>' . get_lang('Date') . '</b></td>
-                                                <td width="400px">' . api_convert_and_format_date($now, DATE_TIME_FORMAT_LONG) . '</td>
-                                            </tr>
-                                            <tr>
-                                                <td width="100px"><b>' . get_lang('Topic') . '</b></td>
-                                                <td width="400px">' . $subject . '</td>
-                                            </tr>
-                                            <tr>
-                                                <td width="100px"><b>' . get_lang('Description') . '</b></td>
-                                                <td width="400px">' . $content . '</td>
-                                            </tr>
-                                        </table>';
 
                     // Send email to "other area" email
                     api_mail_html(
@@ -380,6 +398,44 @@ class TicketManager
                     );
                 }
 
+                if (!empty($category_id)) {
+                    $categoryInfo = TicketManager::getCategory($category_id);
+                    if ($plugin->get('warn_admin_no_user_in_category')) {
+
+                        $usersInCategory = TicketManager::getUsersInCategory($category_id);
+
+                        if (empty($usersInCategory)) {
+
+                            $subject = sprintf(
+                                $plugin->get_lang('WarningCategoryXDoesntHaveUsers'),
+                                $categoryInfo['name']
+                            );
+
+                            $message = '<h2>'.$plugin->get_lang('TicketInformation').'</h2><br />'.$helpDeskMessage;
+
+                            if ($plugin->get('send_warning_to_all_admins')) {
+                                $admins = UserManager::get_all_administrators();
+                                foreach ($admins as $userId => $data) {
+                                    if ($data['active']) {
+                                        MessageManager::send_message_simple(
+                                            $userId,
+                                            $subject,
+                                            $message
+                                        );
+                                    }
+                                }
+                            } else {
+                                MessageManager::send_message_simple(
+                                    api_get_user_id(),
+                                    $subject,
+                                    $message
+                                );
+                            }
+                        }
+                    }
+                }
+
+
                 return true;
             } else {
 

+ 4 - 2
plugin/ticket/src/ticket_plugin.class.php

@@ -28,11 +28,13 @@ class TicketPlugin extends Plugin
         $settings = array(
             'tool_enable' => 'boolean',
             'allow_student_add' => 'boolean',
-            'allow_category_edition' => 'boolean'
+            'allow_category_edition' => 'boolean',
+            'warn_admin_no_user_in_category' => 'boolean',
+            'send_warning_to_all_admins' => 'boolean'
         );
 
         parent::__construct(
-            '1.0',
+            '2.0',
             'Kenny Rodas Chavez, Genesis Lopez, Francis Gonzales, Yannick Warnier, Julio Montoya',
             $settings
         );