Fix ticket plugin

remotes/angel/1.11.x
jmontoyaa 9 years ago
parent c711048026
commit 02497755d1
  1. 30
      main/admin/configure_plugin.php
  2. 14
      main/inc/lib/api.lib.php
  3. 10
      main/inc/lib/plugin.class.php
  4. 3
      main/inc/lib/plugin.lib.php
  5. 5
      plugin/ticket/src/categories.php
  6. 5
      plugin/ticket/src/myticket.php
  7. 65
      plugin/ticket/src/ticket.class.php
  8. 6
      plugin/ticket/src/ticket_details.php
  9. 11
      plugin/vchamilo/index.php
  10. 2
      plugin/vchamilo/plugin.php

@ -25,17 +25,23 @@ if (!in_array($pluginName, $installedPlugins) || empty($pluginInfo)) {
global $_configuration; global $_configuration;
$message = null; $message = '';
$content = null; $content = '';
$currentUrl = api_get_self() . "?name=$pluginName"; $currentUrl = api_get_self() . "?name=$pluginName";
if (isset($pluginInfo['settings_form'])) { if (isset($pluginInfo['settings_form'])) {
/** @var FormValidator $form */
$form = $pluginInfo['settings_form']; $form = $pluginInfo['settings_form'];
if (isset($form)) { if (isset($form)) {
//We override the form attributes
// We override the form attributes
$attributes = array('action' => $currentUrl, 'method' => 'POST'); $attributes = array('action' => $currentUrl, 'method' => 'POST');
$form->updateAttributes($attributes); $form->updateAttributes($attributes);
if (isset($pluginInfo['settings'])) {
$form->setDefaults($pluginInfo['settings']);
}
$content = Display::page_header($pluginInfo['title']); $content = Display::page_header($pluginInfo['title']);
$content .= $form->toHtml(); $content .= $form->toHtml();
} }
@ -46,8 +52,6 @@ if (isset($pluginInfo['settings_form'])) {
if (isset($form)) { if (isset($form)) {
if ($form->validate()) { if ($form->validate()) {
$values = $form->exportValues(); $values = $form->exportValues();
//api_delete_category_settings_by_subkey($pluginName);
$accessUrlId = api_get_current_access_url_id(); $accessUrlId = api_get_current_access_url_id();
api_delete_settings_params( api_delete_settings_params(
@ -64,7 +68,8 @@ if (isset($form)) {
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
api_add_setting( api_add_setting(
$value, Database::escape_string($pluginName . '_' . $key), $value,
Database::escape_string($pluginName . '_' . $key),
$pluginName, $pluginName,
'setting', 'setting',
'Plugins', 'Plugins',
@ -76,28 +81,23 @@ if (isset($form)) {
1 1
); );
} }
if (isset($values['show_main_menu_tab'])) { if (isset($values['show_main_menu_tab'])) {
$objPlugin = $pluginInfo['plugin_class']::create(); $objPlugin = $pluginInfo['plugin_class']::create();
$objPlugin->manageTab($values['show_main_menu_tab']); $objPlugin->manageTab($values['show_main_menu_tab']);
} }
$message = Display::return_message(get_lang('Updated'), 'success'); Display::addFlash(Display::return_message(get_lang('Updated'), 'success'));
Session::write('message', $message);
header("Location: $currentUrl"); header("Location: $currentUrl");
exit; exit;
} else { } else {
foreach ($form->_errors as $error) { foreach ($form->_errors as $error) {
$message .= Display::return_message($error, 'error'); Display::addFlash(Display::return_message($error, 'error'));
} }
} }
} }
if (Session::has('message')) {
$message = Session::read('message');
}
$interbreadcrumb[] = array( $interbreadcrumb[] = array(
'url' => api_get_path(WEB_CODE_PATH) . 'admin/index.php', 'url' => api_get_path(WEB_CODE_PATH) . 'admin/index.php',
'name' => get_lang('PlatformAdmin') 'name' => get_lang('PlatformAdmin')
@ -108,7 +108,7 @@ $interbreadcrumb[] = array(
); );
$tpl = new Template($pluginName, true, true, false, true, false); $tpl = new Template($pluginName, true, true, false, true, false);
$tpl->assign('message', $message); $tpl->assign('message', '');
$tpl->assign('content', $content); $tpl->assign('content', $content);
$tpl->display_one_col_template(); $tpl->display_one_col_template();

@ -5274,7 +5274,19 @@ function api_delete_category_settings_by_subkey($subkey, $access_url_id = 1) {
* @param string $c * @param string $c
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
function api_add_setting($val, $var, $sk = null, $type = 'textfield', $c = null, $title = '', $com = '', $sc = null, $skt = null, $a = 1, $v = 0) { function api_add_setting(
$val,
$var,
$sk = null,
$type = 'textfield',
$c = null,
$title = '',
$com = '',
$sc = null,
$skt = null,
$a = 1,
$v = 0
) {
if (empty($var) || !isset($val)) { return false; } if (empty($var) || !isset($val)) { return false; }
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$var = Database::escape_string($var); $var = Database::escape_string($var);

@ -81,8 +81,10 @@ class Plugin
if ($form = $this->get_settings_form()) { if ($form = $this->get_settings_form()) {
$result['settings_form'] = $form; $result['settings_form'] = $form;
foreach ($this->fields as $name => $type) { foreach ($this->fields as $name => $type) {
$value = $this->get($name); $value = $this->get($name);
if (is_array($type)) { if (is_array($type)) {
$value = $type['options']; $value = $type['options'];
} }
@ -183,13 +185,12 @@ class Plugin
foreach ($this->fields as $name => $type) { foreach ($this->fields as $name => $type) {
$options = null; $options = null;
if (is_array($type) && isset($type['type']) && $type['type'] === "select") { if (is_array($type) && isset($type['type']) && $type['type'] === 'select') {
$options = $type['options']; $options = $type['options'];
$type = $type['type']; $type = $type['type'];
} }
$value = $this->get($name); $value = $this->get($name);
$defaults[$name] = $value; $defaults[$name] = $value;
$type = isset($type) ? $type : 'text'; $type = isset($type) ? $type : 'text';
@ -267,7 +268,8 @@ class Plugin
{ {
$settings = $this->get_settings(); $settings = $this->get_settings();
foreach ($settings as $setting) { foreach ($settings as $setting) {
if ($setting['variable'] == ($this->get_name() . '_' . $name)) { if ($setting['variable'] == $this->get_name() . '_' . $name) {
return $setting['selected_value']; return $setting['selected_value'];
} }
} }
@ -281,7 +283,7 @@ class Plugin
*/ */
public function get_settings() public function get_settings()
{ {
if (is_null($this->settings)) { if (empty($this->settings)) {
$settings = api_get_settings_params( $settings = api_get_settings_params(
array( array(
"subkey = ? AND category = ? AND type = ? " => array($this->get_name(), 'Plugins', 'setting') "subkey = ? AND category = ? AND type = ? " => array($this->get_name(), 'Plugins', 'setting')

@ -421,12 +421,13 @@ class AppPlugin
require $plugin_file; require $plugin_file;
} }
//extra options // Extra options
$plugin_settings = api_get_settings_params( $plugin_settings = api_get_settings_params(
array( array(
"subkey = ? AND category = ? AND type = ? " => array($plugin_name, 'Plugins','setting') "subkey = ? AND category = ? AND type = ? " => array($plugin_name, 'Plugins','setting')
) )
); );
$settings_filtered = array(); $settings_filtered = array();
foreach ($plugin_settings as $item) { foreach ($plugin_settings as $item) {
$settings_filtered[$item['variable']] = $item['selected_value']; $settings_filtered[$item['variable']] = $item['selected_value'];

@ -63,7 +63,10 @@ if (isset($_GET['action'])) {
'description' => $values['description'], 'description' => $values['description'],
'total_tickets' => 0, 'total_tickets' => 0,
'sys_insert_user_id' => api_get_user_id(), 'sys_insert_user_id' => api_get_user_id(),
'sys_insert_datetime' => api_get_utc_datetime() 'sys_insert_datetime' => api_get_utc_datetime(),
'category_id' => 0,
'project_id' => 0,
'course_required' => ''
]; ];
TicketManager::addCategory($params); TicketManager::addCategory($params);

@ -227,6 +227,11 @@ if ($isAdmin) {
); );
} }
echo Display::url(
Display::return_icon('settings.png'),
api_get_path(WEB_CODE_PATH) . 'admin/configure_plugin.php?name=ticket'
);
echo '</span>'; echo '</span>';
} }

@ -127,7 +127,6 @@ class TicketManager
} }
/** /**
* @param int $id
* @param array $params * @param array $params
*/ */
public static function addCategory($params) public static function addCategory($params)
@ -185,7 +184,8 @@ class TicketManager
$table = Database::get_main_table(TABLE_TICKET_CATEGORY_REL_USER); $table = Database::get_main_table(TABLE_TICKET_CATEGORY_REL_USER);
$userId = intval($userId); $userId = intval($userId);
$categoryId = intval($categoryId); $categoryId = intval($categoryId);
$sql = "SELECT * FROM $table WHERE category_id = $categoryId AND user_id = $userId"; $sql = "SELECT * FROM $table
WHERE category_id = $categoryId AND user_id = $userId";
$result = Database::query($sql); $result = Database::query($sql);
return Database::num_rows($result) > 0; return Database::num_rows($result) > 0;
@ -516,6 +516,7 @@ class TicketManager
$ticket_id, get_lang('MessageResent'), $studentMessage, null, 1 $ticket_id, get_lang('MessageResent'), $studentMessage, null, 1
); );
} }
return true; return true;
} else { } else {
@ -525,6 +526,7 @@ class TicketManager
/** /**
* Assign ticket to admin * Assign ticket to admin
*
* @param int $ticket_id * @param int $ticket_id
* @param int $user_id * @param int $user_id
*/ */
@ -635,75 +637,62 @@ class TicketManager
) { ) {
global $data_files, $plugin; global $data_files, $plugin;
$ticket_id = intval($ticket_id); $ticket_id = intval($ticket_id);
$subject = Database::escape_string($subject);
$content = Database::escape_string($content);
$user_id = intval($user_id); $user_id = intval($user_id);
$status = Database::escape_string($status);
$table_support_messages = Database::get_main_table(TABLE_TICKET_MESSAGE); $table_support_messages = Database::get_main_table(TABLE_TICKET_MESSAGE);
$table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET); $table_support_tickets = Database::get_main_table(TABLE_TICKET_TICKET);
$table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS); $table_support_message_attachments = Database::get_main_table(TABLE_TICKET_MESSAGE_ATTACHMENTS);
if ($sendConfirmation) { if ($sendConfirmation) {
$form = '<form action="ticket_details.php?ticket_id=' . $ticket_id . '" id="confirmticket" method="POST" > $form = '<form action="ticket_details.php?ticket_id=' . $ticket_id . '" id="confirmticket" method="POST" >
<p>' . $plugin->get_lang('TicketWasThisAnswerSatisfying') . '</p> <p>' . $plugin->get_lang('TicketWasThisAnswerSatisfying') . '</p>
<button name="response" id="responseyes" value="1">' . get_lang('Yes') . '</button> <button class="btn btn-primary responseyes" name="response" id="responseyes" value="1">' . get_lang('Yes') . '</button>
<button name="response" id="responseno" value="0">' . get_lang('No') . '</button> <button class="btn btn-danger responseno" name="response" id="responseno" value="0">' . get_lang('No') . '</button>
</form>'; </form>';
$content .= $form; $content .= $form;
Database::query( Database::query(
"UPDATE $table_support_tickets "UPDATE $table_support_tickets
SET status_id='".self::STATUS_UNCONFIRMED."' SET status_id = '".self::STATUS_UNCONFIRMED."'
WHERE ticket_id = '$ticket_id'" WHERE ticket_id = '$ticket_id'"
); );
} }
$sql = "SELECT COUNT(*) as total_messages $sql = "SELECT COUNT(*) as total_messages
FROM $table_support_messages FROM $table_support_messages
WHERE ticket_id ='$ticket_id'"; WHERE ticket_id = $ticket_id";
$result = Database::query($sql); $result = Database::query($sql);
$obj = Database::fetch_object($result); $obj = Database::fetch_object($result);
$message_id = $obj->total_messages + 1; $message_id = $obj->total_messages + 1;
$now = api_get_utc_datetime(); $now = api_get_utc_datetime();
// insert msg
$sql = "INSERT INTO $table_support_messages ( $params = [
ticket_id, 'ticket_id' => $ticket_id,
message_id, 'message_id' => $message_id,
subject, 'subject' => $subject,
message, 'message' => $content,
ip_address, 'ip_address' => $_SERVER['REMOTE_ADDR'],
sys_insert_user_id, 'sys_insert_user_id' => $user_id,
sys_insert_datetime, 'sys_insert_datetime' => $now,
sys_lastedit_user_id, 'sys_lastedit_user_id' => $user_id,
sys_lastedit_datetime, 'sys_lastedit_datetime' => $now,
status 'status' => $status
) VALUES ( ];
'$ticket_id', Database::insert($table_support_messages, $params);
'$message_id',
'$subject',
'$content',
'" . Database::escape_string($_SERVER['REMOTE_ADDR']) . "',
'$user_id',
'" . $now . "',
'$user_id',
'" . $now . "',
'$status'
)";
Database::query($sql);
// update_total_message // update_total_message
$sql = "UPDATE $table_support_tickets $sql = "UPDATE $table_support_tickets
SET sys_lastedit_user_id ='$user_id', SET
sys_lastedit_user_id ='$user_id',
sys_lastedit_datetime ='$now', sys_lastedit_datetime ='$now',
total_messages = ( total_messages = (
SELECT COUNT(*) as total_messages SELECT COUNT(*) as total_messages
FROM $table_support_messages FROM $table_support_messages
WHERE ticket_id ='$ticket_id' WHERE ticket_id ='$ticket_id'
) )
WHERE ticket_id ='$ticket_id' "; WHERE ticket_id = $ticket_id ";
Database::query($sql); Database::query($sql);
$sql = "SELECT COUNT(*) as total_attach $sql = "SELECT COUNT(*) as total_attach
FROM $table_support_message_attachments FROM $table_support_message_attachments
WHERE ticket_id ='$ticket_id' AND message_id = '$message_id'"; WHERE ticket_id = $ticket_id AND message_id = $message_id";
$result = Database::query($sql); $result = Database::query($sql);
$obj = Database::fetch_object($result); $obj = Database::fetch_object($result);

@ -17,10 +17,10 @@ $interbreadcrumb[] = array('url' => 'myticket.php', 'name' => $plugin->get_lang(
$interbreadcrumb[] = array('url' => '#', 'name' => $plugin->get_lang('TicketDetail')); $interbreadcrumb[] = array('url' => '#', 'name' => $plugin->get_lang('TicketDetail'));
$disableReponseButtons = ''; $disableReponseButtons = '';
if ($isAdmin) { /*if ($isAdmin) {
$disableReponseButtons = "$('#responseyes').attr('disabled', 'disabled'); $disableReponseButtons = "$('#responseyes').attr('disabled', 'disabled');
$('#responseno').attr('disabled', 'disabled');"; $('#responseno').attr('disabled', 'disabled');";
} }*/
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(document).ready(function() { $(document).ready(function() {
@ -43,7 +43,7 @@ $(document).ready(function() {
$( "#dialog-form" ).dialog( "open" ); $( "#dialog-form" ).dialog( "open" );
}); });
$("input#responseyes").click(function () { $(".responseyes").click(function () {
if(!confirm("' . $plugin->get_lang('AreYouSure') . ' : ' . strtoupper(get_lang('Yes')) . '. ' . $plugin->get_lang('IfYouAreSureTheTicketWillBeClosed') . '")){ if(!confirm("' . $plugin->get_lang('AreYouSure') . ' : ' . strtoupper(get_lang('Yes')) . '. ' . $plugin->get_lang('IfYouAreSureTheTicketWillBeClosed') . '")){
return false; return false;
} }

@ -18,15 +18,7 @@ $_template['show_message'] = true;
$_template['title'] = $plugininstance->get_lang('hostlist'); $_template['title'] = $plugininstance->get_lang('hostlist');
$tablename = Database::get_main_table('vchamilo'); $tablename = Database::get_main_table('vchamilo');
$sql = " $sql = "SELECT sitename, root_web FROM $tablename WHERE visible = 1";
SELECT
sitename,
root_web
FROM
$tablename
WHERE
visible = 1
";
if ($virtualChamilo == '%'){ if ($virtualChamilo == '%'){
$result = Database::query($sql); $result = Database::query($sql);
@ -36,5 +28,4 @@ if ($virtualChamilo == '%'){
$_template['hosts'][] = $vchamilo; $_template['hosts'][] = $vchamilo;
} }
} }
} else {
} }

@ -59,7 +59,7 @@ $wwwroot = $_configuration['root_web'];
//A simple select //A simple select
$options = array(0 => $plugininstance->get_lang('no'), 1 => $plugininstance->get_lang('yes')); $options = array(0 => $plugininstance->get_lang('no'), 1 => $plugininstance->get_lang('yes'));
$form->addlabel('', '<a class="btn btn-primary" href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php">'. $form->addLabel('', '<a class="btn btn-primary" href="'.api_get_path(WEB_PLUGIN_PATH).'vchamilo/views/manage.php">'.
$plugininstance->get_lang('manage_instances').'</a>'); $plugininstance->get_lang('manage_instances').'</a>');
$form->addElement('header', $plugininstance->get_lang('enabling')); $form->addElement('header', $plugininstance->get_lang('enabling'));
$form->addElement('select', 'enable_virtualisation', $plugininstance->get_lang('enable_virtualisation'), $options); $form->addElement('select', 'enable_virtualisation', $plugininstance->get_lang('enable_virtualisation'), $options);

Loading…
Cancel
Save