/**
  * Print the object user form for notification
  *
  * @param $ID              integer ID of the item
  * @param $options   array
  *
  * @return Nothing (display)
  **/
 function showUserNotificationForm($ID, $options = array())
 {
     global $CFG_GLPI;
     $this->check($ID, UPDATE);
     if (!isset($this->fields['users_id'])) {
         return false;
     }
     $item = new static::$itemtype_1();
     echo "<br><form method='post' action='" . $_SERVER['PHP_SELF'] . "'>";
     echo "<div class='center'>";
     echo "<table class='tab_cadre' width='80%'>";
     echo "<tr class='tab_bg_2'><td>" . $item->getTypeName(1) . "</td>";
     echo "<td>";
     if ($item->getFromDB($this->fields[static::getItilObjectForeignKey()])) {
         echo $item->getField('name');
     }
     echo "</td></tr>";
     $user = new User();
     $default_email = "";
     $emails = array();
     if ($user->getFromDB($this->fields["users_id"])) {
         $default_email = $user->getDefaultEmail();
         $emails = $user->getAllEmails();
     }
     echo "<tr class='tab_bg_2'><td>" . __('User') . "</td>";
     echo "<td>" . $user->getName() . "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Email Followup') . "</td>";
     echo "<td>";
     Dropdown::showYesNo('use_notification', $this->fields['use_notification']);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Email') . "</td>";
     echo "<td>";
     if (count($emails) == 1 && !empty($default_email) && NotificationMail::isUserAddressValid($default_email)) {
         echo $default_email;
     } else {
         if (count($emails) > 1) {
             // Several emails : select in the list
             $emailtab = array();
             foreach ($emails as $new_email) {
                 if ($new_email != $default_email) {
                     $emailtab[$new_email] = $new_email;
                 } else {
                     $emailtab[''] = $new_email;
                 }
             }
             Dropdown::showFromArray("alternative_email", $emailtab, array('value' => $this->fields['alternative_email']));
         } else {
             echo "<input type='text' size='40' name='alternative_email' value='" . $this->fields['alternative_email'] . "'>";
         }
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_2'>";
     echo "<td class='center' colspan='2'>";
     echo "<input type='submit' name='update' value=\"" . _sx('button', 'Save') . "\" class='submit'>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</td></tr>";
     echo "</table></div>";
     Html::closeForm();
 }
Example #2
0
if (isset($_POST['field']) && $_POST["value"] > 0 || isset($_POST['allow_email']) && $_POST['allow_email']) {
    if (preg_match('/[^a-z_\\-0-9]/i', $_POST['field'])) {
        throw new \RuntimeException('Invalid field provided!');
    }
    $default_email = "";
    $emails = array();
    if (isset($_POST['typefield']) && $_POST['typefield'] == 'supplier') {
        $supplier = new Supplier();
        if ($supplier->getFromDB($_POST["value"])) {
            $default_email = $supplier->fields['email'];
        }
    } else {
        $user = new User();
        if ($user->getFromDB($_POST["value"])) {
            $default_email = $user->getDefaultEmail();
            $emails = $user->getAllEmails();
        }
    }
    $user_index = 0;
    if (isset($_POST['_user_index'])) {
        $user_index = $_POST['_user_index'];
    }
    echo __('Email followup') . '&nbsp;';
    $default_notif = true;
    if (isset($_POST['use_notification'][$user_index])) {
        $default_notif = $_POST['use_notification'][$user_index];
    }
    if (isset($_POST['alternative_email'][$user_index]) && !empty($_POST['alternative_email'][$user_index]) && empty($default_email)) {
        if (NotificationMail::isUserAddressValid($_POST['alternative_email'][$user_index])) {
            $default_email = $_POST['alternative_email'][$user_index];
        } else {