Reminder::showForm PHP Method

showForm() public method

Print the reminder form
public showForm ( $ID, $options = [] )
$ID integer Id of the item to print
$options array of possible options: - target filename : where to go when done. - from_planning_ajax : set to disable planning form part
    function showForm($ID, $options = array())
    {
        global $CFG_GLPI;
        $this->initForm($ID, $options);
        $rand = mt_rand();
        // Show Reminder or blank form
        $onfocus = "";
        if (!$ID > 0) {
            // Create item : do getempty before check right to set default values
            $onfocus = "onfocus=\"if (this.value=='" . $this->fields['name'] . "') this.value='';\"";
        }
        $canedit = $this->can($ID, UPDATE);
        $this->showFormHeader($options);
        echo "<tr class='tab_bg_2'><td colspan='2'>" . __('Title') . "</td>";
        echo "<td colspan='2'>";
        if (!$ID) {
            echo "<input type='hidden' name='users_id' value='" . $this->fields['users_id'] . "'>\n";
        }
        if ($canedit) {
            Html::autocompletionTextField($this, "name", array('size' => '80', 'entity' => -1, 'user' => $this->fields["users_id"], 'option' => $onfocus));
        } else {
            echo $this->fields['name'];
        }
        if (isset($options['from_planning_edit_ajax']) && $options['from_planning_edit_ajax']) {
            echo Html::hidden('from_planning_edit_ajax');
        }
        echo "</td>";
        echo "</tr>";
        if (!isset($options['from_planning_ajax'])) {
            echo "<tr class='tab_bg_2'>";
            echo "<td colspan='2'>" . __('Visibility') . "</td>";
            echo "<td colspan='2'>";
            echo '<table><tr><td>';
            echo __('Begin') . '</td><td>';
            Html::showDateTimeField("begin_view_date", array('value' => $this->fields["begin_view_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
            echo '</td><td>' . __('End') . '</td><td>';
            Html::showDateTimeField("end_view_date", array('value' => $this->fields["end_view_date"], 'timestep' => 1, 'maybeempty' => true, 'canedit' => $canedit));
            echo '</td></tr></table>';
            echo "</td>";
            echo "</tr>";
        }
        echo "<tr class='tab_bg_2'>";
        echo "<td colspan='2'>" . __('Status') . "</td>";
        echo "<td colspan='2'>";
        if ($canedit) {
            Planning::dropdownState("state", $this->fields["state"]);
        } else {
            echo Planning::getState($this->fields["state"]);
        }
        echo "</td>\n";
        echo "</tr>\n";
        echo "<tr class='tab_bg_2'><td  colspan='2'>" . __('Calendar') . "</td>";
        echo "<td colspan='2'>";
        if (isset($options['from_planning_ajax']) && $options['from_planning_ajax']) {
            echo Html::hidden('plan[begin]', array('value' => $options['begin']));
            echo Html::hidden('plan[end]', array('value' => $options['end']));
            printf(__('From %1$s to %2$s'), Html::convDateTime($options["begin"]), Html::convDateTime($options["end"]));
            echo "</td>";
        } else {
            if ($canedit) {
                echo "<script type='text/javascript' >\n";
                echo "function showPlan{$rand}() {\n";
                echo Html::jsHide("plan{$rand}");
                $params = array('action' => 'add_event_classic_form', 'form' => 'remind', 'users_id' => $this->fields["users_id"], 'itemtype' => $this->getType(), 'items_id' => $this->getID());
                if ($ID && $this->fields["is_planned"]) {
                    $params['begin'] = $this->fields["begin"];
                    $params['end'] = $this->fields["end"];
                }
                Ajax::updateItemJsCode("viewplan{$rand}", $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params);
                echo "}";
                echo "</script>\n";
            }
            if (!$ID || !$this->fields["is_planned"]) {
                if (Session::haveRightsOr("planning", array(Planning::READMY, Planning::READGROUP, Planning::READALL))) {
                    echo "<div id='plan{$rand}' onClick='showPlan{$rand}()'>\n";
                    echo "<a href='#' class='vsubmit'>" . __('Add to schedule') . "</a>";
                }
            } else {
                if ($canedit) {
                    echo "<div id='plan{$rand}' onClick='showPlan{$rand}()'>\n";
                    echo "<span class='showplan'>";
                }
                //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 "</span>";
                }
            }
            if ($canedit) {
                echo "</div>\n";
                echo "<div id='viewplan{$rand}'>\n</div>\n";
            }
            echo "</td>";
            if ($ID && $this->fields["is_planned"] && PlanningRecall::isAvailable()) {
                echo "<td>" . _x('Planning', 'Reminder') . "</td>";
                echo "<td>";
                if ($canedit) {
                    PlanningRecall::dropdown(array('itemtype' => 'Reminder', 'items_id' => $ID));
                } else {
                    // No edit right : use specific Planning Recall Form
                    PlanningRecall::specificForm(array('itemtype' => 'Reminder', 'items_id' => $ID));
                }
                echo "</td>";
            }
        }
        echo "</tr>\n";
        echo "<tr class='tab_bg_2'><td>" . __('Description') . "</td>" . "<td colspan='3'>";
        if ($canedit) {
            $rand = mt_rand();
            echo "<textarea rows='15' name='text' id='text{$rand}'>" . $this->fields["text"] . "</textarea>";
            Html::initEditorSystem('text' . $rand);
        } else {
            echo "<div  id='kbanswer'>";
            echo Toolbox::unclean_html_cross_side_scripting_deep($this->fields["text"]);
            echo "</div>";
        }
        echo "</td></tr>\n";
        $this->showFormButtons($options);
        return true;
    }

Usage Example

Example #1
0
                        case 'Profile':
                            if (isset($_POST['profiles_id']) && $_POST['profiles_id']) {
                                $item = new Profile_Reminder();
                            }
                            break;
                        case 'Entity':
                            $item = new Entity_Reminder();
                            break;
                    }
                    if (!is_null($item)) {
                        $item->add($_POST);
                        Event::log($_POST["reminders_id"], "reminder", 4, "tools", sprintf(__('%s adds a target'), $_SESSION["glpiname"]));
                    }
                }
                Html::back();
            } else {
                if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
                    Html::helpHeader(Reminder::getTypeName(2), '', $_SESSION["glpiname"]);
                } else {
                    Html::header(Reminder::getTypeName(2), '', "utils", "reminder");
                }
                $remind->showForm($_GET["id"]);
                if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
                    Html::helpFooter();
                } else {
                    Html::footer();
                }
            }
        }
    }
}