\n";
echo "";
}
//TRANS: %1$s is the begin date, %2$s is the end date
printf(__('From %1$s to %2$s'), Html::convDateTime($this->fields["begin"]),
Html::convDateTime($this->fields["end"]));
if ($canedit) {
echo "";
}
}
if ($canedit) {
echo "
\n";
$this->showFormButtons($options);
return true;
}
/**
* Populate the planning with planned reminder
*
* @param $options array of possible options:
* - who ID of the user (0 = undefined)
* - who_group ID of the group of users (0 = undefined)
* - begin Date
* - end Date
* - color
* - event_type_color
* - check_planned (boolean)
* - display_done_events (boolean)
*
* @return array of planning item
**/
static function populatePlanning($options=array()) {
global $DB, $CFG_GLPI;
$default_options = array(
'genical' => false,
'color' => '',
'event_type_color' => '',
'check_planned' => false,
'display_done_events' => true,
);
$options = array_merge($default_options, $options);
$interv = array();
$reminder = new self;
if (!isset($options['begin']) || ($options['begin'] == 'NULL')
|| !isset($options['end']) || ($options['end'] == 'NULL')) {
return $interv;
}
$who = $options['who'];
$who_group = $options['who_group'];
$begin = $options['begin'];
$end = $options['end'];
$readpub = $readpriv = "";
$joinstoadd = self::addVisibilityJoins(true);
// See public reminder ?
if (!$options['genical']
&& $who === Session::getLoginUserID()
&& self::canView()) {
$readpub = self::addVisibilityRestrict();
}
// See my private reminder ?
if (($who_group === "mine") || ($who === Session::getLoginUserID())) {
$readpriv = "(`glpi_reminders`.`users_id` = '".Session::getLoginUserID()."')";
} else {
if ($who > 0) {
$readpriv = "`glpi_reminders`.`users_id` = '$who'";
}
if ($who_group > 0) {
if (!empty($readpriv)) {
$readpriv .= " OR ";
}
$readpriv .= " `glpi_groups_reminders`.`groups_id` = '$who_group'";
}
if (!empty($readpriv)) {
$readpriv = '('.$readpriv.')';
}
}
$ASSIGN = '';
if (!empty($readpub)
&& !empty($readpriv)) {
$ASSIGN = "($readpub OR $readpriv)";
} else if ($readpub) {
$ASSIGN = $readpub;
} else {
$ASSIGN = $readpriv;
}
$PLANNED = '';
if ($options['check_planned']) {
$PLANNED = "AND state != ".Planning::INFO;
}
$DONE_EVENTS = '';
if (!$options['display_done_events']) {
$DONE_EVENTS = "AND (state = ".Planning::TODO."
OR (state = ".Planning::INFO."
AND `end` > NOW()))";
}
if ($ASSIGN) {
$query2 = "SELECT DISTINCT `glpi_reminders`.*
FROM `glpi_reminders`
$joinstoadd
WHERE `glpi_reminders`.`is_planned` = '1'
AND $ASSIGN
$PLANNED
$DONE_EVENTS
AND `begin` < '$end'
AND `end` > '$begin'
ORDER BY `begin`";
$result2 = $DB->query($query2);
if ($DB->numrows($result2) > 0) {
for ($i=0 ; $data=$DB->fetch_assoc($result2) ; $i++) {
if ($reminder->getFromDB($data["id"])
&& $reminder->canViewItem()) {
$key = $data["begin"]."$$"."Reminder"."$$".$data["id"];
$interv[$key]['color'] = $options['color'];
$interv[$key]['event_type_color'] = $options['event_type_color'];
$interv[$key]["itemtype"] = 'Reminder';
$interv[$key]["reminders_id"] = $data["id"];
$interv[$key]["id"] = $data["id"];
if (strcmp($begin,$data["begin"]) > 0) {
$interv[$key]["begin"] = $begin;
} else {
$interv[$key]["begin"] = $data["begin"];
}
if (strcmp($end,$data["end"]) < 0) {
$interv[$key]["end"] = $end;
} else {
$interv[$key]["end"] = $data["end"];
}
$interv[$key]["name"] = Html::resume_text($data["name"], $CFG_GLPI["cut"]);
$interv[$key]["text"]
= Html::resume_text(Html::clean(Toolbox::unclean_cross_side_scripting_deep($data["text"])),
$CFG_GLPI["cut"]);
$interv[$key]["users_id"] = $data["users_id"];
$interv[$key]["state"] = $data["state"];
$interv[$key]["state"] = $data["state"];
$interv[$key]["url"] = $CFG_GLPI["root_doc"]."/front/reminder.form.php?id=".
$data['id'];
$interv[$key]["ajaxurl"] = $CFG_GLPI["root_doc"]."/ajax/planning.php".
"?action=edit_event_form".
"&itemtype=Reminder".
"&id=".$data['id'].
"&url=".$interv[$key]["url"];
$interv[$key]["editable"] = $reminder->canUpdateItem();
}
}
}
}
return $interv;
}
/**
* Display a Planning Item
*
* @param $val Array of the item to display
*
* @return Already planned information
**/
static function getAlreadyPlannedInformation(array $val) {
global $CFG_GLPI;
//TRANS: %1$s is the begin date, %2$s is the end date
$beginend = sprintf(__('From %1$s to %2$s'),
Html::convDateTime($val["begin"]), Html::convDateTime($val["end"]));
$out = sprintf(__('%1$s: %2$s'), $beginend,
"".Html::resume_text($val["name"],80)."");
return $out;
}
/**
* Display a Planning Item
*
* @param $val array of the item to display
* @param $who ID of the user (0 if all)
* @param $type position of the item in the time block (in, through, begin or end)
* (default '')
* @param $complete complete display (more details) (default 0)
*
* @return Nothing (display function)
**/
static function displayPlanningItem(array $val, $who, $type="", $complete=0) {
global $CFG_GLPI;
$html = "";
$rand = mt_rand();
$users_id = ""; // show users_id reminder
$img = "rdv_private.png"; // default icon for reminder
if ($val["users_id"] != Session::getLoginUserID()) {
$users_id = " ".sprintf(__('%1$s: %2$s'), __('By'), getUserName($val["users_id"]));
$img = "rdv_public.png";
}
$html.= " ";
$html.= "";
$html.= $users_id;
$html.= "";
$recall = '';
if (isset($val['reminders_id'])) {
$pr = new PlanningRecall();
if ($pr->getFromDBForItemAndUser($val['itemtype'], $val['reminders_id'],
Session::getLoginUserID())) {
$recall = " ".sprintf(__('Recall on %s'),
Html::convDateTime($pr->fields['when'])).
"";
}
}
if ($complete) {
$html.= "".Planning::getState($val["state"])." ";
$html.= "
".$val["text"].$recall."
";
} else {
$html.= Html::showToolTip("".Planning::getState($val["state"])."
".$val["text"].$recall,
array('applyto' => "reminder_".$val["reminders_id"].$rand,
'display' => false));
}
return $html;
}
/**
* Show list for central view
*
* @param $personal boolean : display reminders created by me ? (true by default)
*
* @return Nothing (display function)
**/
static function showListForCentral($personal=true) {
global $DB, $CFG_GLPI;
$users_id = Session::getLoginUserID();
$today = date('Y-m-d');
$now = date('Y-m-d H:i:s');
$restrict_visibility = " AND (`glpi_reminders`.`begin_view_date` IS NULL
OR `glpi_reminders`.`begin_view_date` < '$now')
AND (`glpi_reminders`.`end_view_date` IS NULL
OR `glpi_reminders`.`end_view_date` > '$now') ";
if ($personal) {
/// Personal notes only for central view
if ($_SESSION['glpiactiveprofile']['interface'] == 'helpdesk') {
return false;
}
$query = "SELECT `glpi_reminders`.*
FROM `glpi_reminders`
WHERE `glpi_reminders`.`users_id` = '$users_id'
AND (`glpi_reminders`.`end` >= '$today'
OR `glpi_reminders`.`is_planned` = '0')
$restrict_visibility
ORDER BY `glpi_reminders`.`name`";
$titre = "".
_n('Personal reminder', 'Personal reminders', Session::getPluralNumber())."";
} else {
// Show public reminders / not mines : need to have access to public reminders
if (!self::canView()) {
return false;
}
$restrict_user = '1';
// Only personal on central so do not keep it
if ($_SESSION['glpiactiveprofile']['interface'] == 'central') {
$restrict_user = "`glpi_reminders`.`users_id` <> '$users_id'";
}
$query = "SELECT DISTINCT `glpi_reminders`.*
FROM `glpi_reminders` ".
self::addVisibilityJoins()."
WHERE $restrict_user
$restrict_visibility
AND ".self::addVisibilityRestrict()."
ORDER BY `glpi_reminders`.`name`";
if ($_SESSION['glpiactiveprofile']['interface'] != 'helpdesk') {
$titre = "".
_n('Public reminder', 'Public reminders', Session::getPluralNumber())."";
} else {
$titre = _n('Public reminder', 'Public reminders', Session::getPluralNumber());
}
}
$result = $DB->query($query);
$nb = $DB->numrows($result);
echo "
\n";
}
/**
* Show visibility config for a reminder
**/
function showVisibility() {
global $DB, $CFG_GLPI;
$ID = $this->fields['id'];
$canedit = $this->canEdit($ID);
$rand = mt_rand();
$nb = count($this->users) + count($this->groups) + count($this->profiles)
+ count($this->entities);
if ($canedit) {
echo "
";
echo "
";
}
echo "
";
if ($canedit && $nb) {
Html::openMassiveActionsForm('mass'.__CLASS__.$rand);
$massiveactionparams
= array('num_displayed'
=> min($_SESSION['glpilist_limit'], $nb),
'container'
=> 'mass'.__CLASS__.$rand,
'specific_actions'
=> array('delete' => _x('button', 'Delete permanently')) );
if ($this->fields['users_id'] != Session::getLoginUserID()) {
$massiveactionparams['confirm']
= __('Caution! You are not the author of this element. Delete targets can result in loss of access to that element.');
}
Html::showMassiveActions($massiveactionparams);
}
echo "