Skip to content

Commit

Permalink
Merge pull request #18 from mate-infotel/reminder
Browse files Browse the repository at this point in the history
Reminder
  • Loading branch information
mate-infotel authored Sep 2, 2019
2 parents f956ba7 + 188dea3 commit 214e783
Show file tree
Hide file tree
Showing 12 changed files with 1,307 additions and 19 deletions.
70 changes: 70 additions & 0 deletions ajax/viewsubitem_reminder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* ---------------------------------------------------------------------
* GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2015-2018 Teclib' and contributors.
*
* http://glpi-project.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* GLPI is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GLPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GLPI. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/

include('../../../inc/includes.php');
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

if (!isset($_POST['type'])) {
exit();
}
if (!isset($_POST['parenttype'])) {
exit();
}

if (($item = getItemForItemtype($_POST['type']))
&& ($parent = getItemForItemtype($_POST['parenttype']))) {
if (isset($_POST[$parent->getForeignKeyField()])
&& isset($_POST["id"])
&& $parent->getFromDB($_POST[$parent->getForeignKeyField()])) {

$reminderName = PluginSatisfactionSurveyReminder::PREDEFINED_REMINDER_OPTION_NAME;

$options = [
'parent' => $parent
];

if(isset( $_POST[$reminderName])){
$options[$reminderName] = intval($_POST[$reminderName]);
}

$item->showForm($_POST["id"], $options);

} else {
echo __('Access denied');
}
}

Html::ajaxFooter();
33 changes: 33 additions & 0 deletions front/surveyreminder.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

include('../../../inc/includes.php');

Session::checkLoginUser();

$reminder = new PluginSatisfactionSurveyReminder();

if (isset($_POST["add"])) {

$input = $_POST;

if(isset($input[$reminder::PREDEFINED_REMINDER_OPTION_NAME])){
$input = $reminder->generatePredefinedReminderForAdd($input);
}

$reminder->check(-1, CREATE, $input);
$reminder->add($input);
Html::back();

} else if (isset($_POST["update"])) {
$reminder->check($_POST['id'], UPDATE);
$reminder->update($_POST);
Html::back();

} else if (isset($_POST["delete"])) {
$reminder->check($_POST['id'], PURGE);
$reminder->delete($_POST);
Html::back();

}

Html::displayErrorAndDie('Lost');
30 changes: 26 additions & 4 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ function plugin_satisfaction_install() {
global $DB;

include_once(GLPI_ROOT . "/plugins/satisfaction/inc/profile.class.php");
include_once(GLPI_ROOT . "/plugins/satisfaction/inc/notificationtargetticket.class.php");

if (!$DB->tableExists("glpi_plugin_satisfaction_surveys")) {
$DB->runFile(GLPI_ROOT . "/plugins/satisfaction/install/sql/empty-1.4.1.sql");
$DB->runFile(GLPI_ROOT . "/plugins/satisfaction/install/sql/empty-1.4.3.sql");

} else {
if (!$DB->fieldExists("glpi_plugin_satisfaction_surveyquestions", "type")) {
$DB->runFile(GLPI_ROOT . "/plugins/satisfaction/install/sql/update-1.1.0.sql");
Expand All @@ -22,10 +24,17 @@ function plugin_satisfaction_install() {
if (!$DB->tableExists("glpi_plugin_satisfaction_surveytranslations")) {
$DB->runFile(GLPI_ROOT . "/plugins/satisfaction/install/sql/update-1.4.1.sql");
}

//version 1.4.3
if (!$DB->tableExists("glpi_plugin_satisfaction_surveyreminders")) {
$DB->runFile(GLPI_ROOT . "/plugins/satisfaction/install/sql/update-1.4.3.sql");
}
}

PluginSatisfactionNotificationTargetTicket::install();
PluginSatisfactionProfile::initProfile();
PluginSatisfactionProfile::createFirstAccess($_SESSION['glpiactiveprofile']['id']);

return true;
}

Expand All @@ -37,10 +46,15 @@ function plugin_satisfaction_uninstall() {

include_once(GLPI_ROOT . "/plugins/satisfaction/inc/profile.class.php");
include_once(GLPI_ROOT . "/plugins/satisfaction/inc/menu.class.php");
include_once(GLPI_ROOT . "/plugins/satisfaction/inc/notificationtargetticket.class.php");

$tables = ["glpi_plugin_satisfaction_surveys",
"glpi_plugin_satisfaction_surveyquestions",
"glpi_plugin_satisfaction_surveyanswers"];
$tables = [
"glpi_plugin_satisfaction_surveys",
"glpi_plugin_satisfaction_surveyquestions",
"glpi_plugin_satisfaction_surveyanswers",
"glpi_plugin_satisfaction_surveyreminders",
"glpi_plugin_satisfaction_surveytranslations"
];

foreach ($tables as $table) {
$DB->query("DROP TABLE IF EXISTS `$table`;");
Expand All @@ -62,5 +76,13 @@ function plugin_satisfaction_uninstall() {

PluginSatisfactionMenu::removeRightsFromSession();

PluginSatisfactionNotificationTargetTicket::uninstall();

CronTask::Register(PluginSatisfactionReminder::class, PluginSatisfactionReminder::CRON_TASK_NAME, DAY_TIMESTAMP);

return true;
}

function plugin_satisfaction_get_events(NotificationTargetTicket $target) {
$target->events['survey_reminder'] = __("Ticket Satisfaction Reminder", 'satisfaction');
}
196 changes: 196 additions & 0 deletions inc/notificationMailing.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php
/*
* @version $Id: HEADER 15930 2011-10-30 15:47:55Z tsmr $
-------------------------------------------------------------------------
resources plugin for GLPI
Copyright (C) 2009-2016 by the resources Development Team.
https://github.com/InfotelGLPI/resources
-------------------------------------------------------------------------
LICENSE
This file is part of resources.
resources is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
resources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with resources. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/

if (!defined('GLPI_ROOT')) {
die("Sorry. You can't access directly to this file");
}

/**
* Class PluginResourcesNotification
*/
class PluginSatisfactionNotificationMailing extends CommonDBTM {

static $rightname = 'plugin_satisfaction';

/**
* Return the localized name of the current Type
* Should be overloaded in each new class
*
* @param integer $nb Number of items
*
* @return string
**/
static function getTypeName($nb = 0) {

return __('Notification satisfaction reminder', 'satisfaction');
}

/**
* Have I the global right to "create" the Object
* May be overloaded if needed (ex KnowbaseItem)
*
* @return booleen
**/
static function canCreate() {
return Session::haveRight(self::$rightname, [CREATE, UPDATE, DELETE]);
}

/**
* Have I the global right to "view" the Object
*
* Default is true and check entity if the objet is entity assign
*
* May be overloaded if needed
*
* @return booleen
**/
static function canView() {
return Session::haveRight(self::$rightname, READ);
}

/**
* Function list items
*
* @param type $ID
*/
public function listItems($ID) {

$rand = mt_rand();

// Start
$start = 0;
if (isset($_REQUEST["start"])) {
$start = $_REQUEST["start"];
}

// Get data
$data = $this->getItems($ID, $start);
if (!empty($data)) {
echo "<div class='center'>";
$dbu = new DbUtils();
Html::printAjaxPager(self::getTypeName(2), $start, $dbu->countElementsInTable($this->getTable()));
echo "<table class='tab_cadre_fixehov'>";
echo "<tr class='tab_bg_1'>";
echo "<th colspan='3'>".self::getTypeName(1)."</th>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<th>".__('User')."</th>";
echo "<th>".__('Date')."</th>";
echo "<th>".__('Type')."</th>";
echo "</tr>";

$dbu = new DbUtils();

foreach ($data as $field) {
echo "<tr class='tab_bg_2'>";
// // User
// echo "<td>".$dbu->formatUserName($field['users_id'], $field['name'], $field['realname'], $field['firstname'])."</td>";
// echo "<td>".Html::convDateTime($field['date_mod'])."</td>";
// echo "<td>".self::getStatus($field['type'])."</td>";
// echo "</tr>";
// Ticket
// TODO
}
echo "</table>";
echo "</div>";
}
}

/**
* Function get items for resource
*
* @global type $DB
* @param type $recordmodels_id
* @param type $start
* @return type
*/
function getItems($resources_id, $start = 0) {
global $DB;

$output = [];

$query = "SELECT `".$this->getTable()."`.`id`,
`glpi_users`.`realname`,
`glpi_users`.`firstname`,
`glpi_users`.`name`,
`".$this->getTable()."`.`type`,
`".$this->getTable()."`.`users_id`,
`".$this->getTable()."`.`date_mod`,
`".$this->getTable()."`.`plugin_resources_resources_id`
FROM ".$this->getTable()."
LEFT JOIN `glpi_users` ON (`".$this->getTable()."`.`users_id` = `glpi_users`.`id`)
WHERE `".$this->getTable()."`.`plugin_resources_resources_id` = ".Toolbox::cleanInteger($resources_id)."
ORDER BY `".$this->getTable()."`.`date_mod` DESC
LIMIT ".intval($start).",".intval($_SESSION['glpilist_limit']);

$result = $DB->query($query);
if ($DB->numrows($result)) {
while ($data = $DB->fetch_assoc($result)) {
$output[$data['id']] = $data;
}
}

return $output;
}

/**
* Function get the Status
*
* @return an array
*/
static function getStatus($value) {
$data = self::getAllStatusArray();
return $data[$value];
}

/**
* Get the SNMP Status list
*
* @return an array
*/
static function getAllStatusArray() {

// To be overridden by class
$tab = ['report' => __('Resource creation', 'resources'),
'other' => __('Other', 'resources')];

return $tab;
}

/**
* if profile deleted
*
* @param \Ticket $resource
*/
static function purgeNotification(Ticket $ticket) {
$temp = new self();
$temp->deleteByCriteria(['tickets_id' => $ticket->getField("id")]);
}
}

Loading

0 comments on commit 214e783

Please sign in to comment.