Example #1
0
 /**
  * Print the contact form
  *
  * @param $ID        integer ID of the item
  * @param $options   array
  *     - target filename : where to go when done.
  *     - withtemplate boolean : template or basic item
  *
  * @return Nothing (display)
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI;
     if (!Config::canView() || !$this->getFromDB($ID)) {
         return false;
     }
     $options['candel'] = false;
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Name') . "</td>";
     echo "<td class ='b'>";
     $name = $this->fields["name"];
     if ($isplug = isPluginItemType($this->fields["itemtype"])) {
         $name = sprintf(__('%1$s - %2$s'), $isplug["plugin"], $name);
     }
     echo $name . "</td>";
     echo "<td rowspan='6' class='middle right'>" . __('Comments') . "</td>";
     echo "<td class='center middle' rowspan='6'>";
     echo "<textarea cols='45' rows='8' name='comment' >" . $this->fields["comment"] . "</textarea>";
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Description') . "</td><td>";
     echo $this->getDescription($ID);
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Run frequency') . "</td><td>";
     $this->dropdownFrequency('frequency', $this->fields["frequency"]);
     echo "</td></tr>";
     $tmpstate = $this->fields["state"];
     echo "<tr class='tab_bg_1'><td>" . __('Status') . "</td><td>";
     if (is_file(GLPI_CRON_DIR . '/' . $this->fields["name"] . '.lock') || is_file(GLPI_CRON_DIR . '/all.lock')) {
         echo "<span class='b'>" . __('System lock') . "</span><br>";
         $tmpstate = self::STATE_DISABLE;
     }
     if ($isplug) {
         $plug = new Plugin();
         if (!$plug->isActivated($isplug["plugin"])) {
             echo "<span class='b'>" . __('Disabled plugin') . "</span><br>";
             $tmpstate = self::STATE_DISABLE;
         }
     }
     if ($this->fields["state"] == self::STATE_RUNNING) {
         echo "<span class='b'>" . $this->getStateName(self::STATE_RUNNING) . "</span>";
     } else {
         self::dropdownState('state', $this->fields["state"]);
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Run mode') . "</td><td>";
     $modes = array();
     if ($this->fields['allowmode'] & self::MODE_INTERNAL) {
         $modes[self::MODE_INTERNAL] = self::getModeName(self::MODE_INTERNAL);
     }
     if ($this->fields['allowmode'] & self::MODE_EXTERNAL) {
         $modes[self::MODE_EXTERNAL] = self::getModeName(self::MODE_EXTERNAL);
     }
     Dropdown::showFromArray('mode', $modes, array('value' => $this->fields['mode']));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Run period') . "</td><td>";
     Dropdown::showNumber('hourmin', array('value' => $this->fields['hourmin'], 'min' => 0, 'max' => 24, 'width' => '35%'));
     echo "&nbsp;->&nbsp;";
     Dropdown::showNumber('hourmax', array('value' => $this->fields['hourmax'], 'min' => 0, 'max' => 24, 'width' => '35%'));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'><td>" . __('Number of days this action logs are stored') . "</td><td>";
     Dropdown::showNumber('logs_lifetime', array('value' => $this->fields['logs_lifetime'], 'min' => 10, 'max' => 360, 'step' => 10, 'toadd' => array(0 => __('Infinite'))));
     echo "</td><td>" . __('Last run') . "</td><td>";
     if (empty($this->fields['lastrun'])) {
         _e('Never');
     } else {
         echo Html::convDateTime($this->fields['lastrun']);
         echo "&nbsp;";
         Html::showSimpleForm(static::getFormURL(), 'resetdate', __('Blank'), array('id' => $ID), $CFG_GLPI['root_doc'] . "/pics/reset.png");
     }
     echo "</td></tr>";
     $label = $this->getParameterDescription();
     echo "<tr class='tab_bg_1'><td>";
     if (empty($label)) {
         echo "&nbsp;</td><td>&nbsp;";
     } else {
         echo $label . "&nbsp;</td><td>";
         Dropdown::showNumber('param', array('value' => $this->fields['param'], 'min' => 0, 'max' => 400));
     }
     echo "</td><td>" . __('Next run') . "</td><td>";
     if ($tmpstate == self::STATE_RUNNING) {
         $launch = false;
     } else {
         $launch = $this->fields['allowmode'] & self::MODE_INTERNAL;
     }
     if ($tmpstate != self::STATE_WAITING) {
         echo $this->getStateName($tmpstate);
     } else {
         if (empty($this->fields['lastrun'])) {
             _e('As soon as possible');
         } else {
             $next = strtotime($this->fields['lastrun']) + $this->fields['frequency'];
             $h = date('H', $next);
             $deb = $this->fields['hourmin'] < 10 ? "0" . $this->fields['hourmin'] : $this->fields['hourmin'];
             $fin = $this->fields['hourmax'] < 10 ? "0" . $this->fields['hourmax'] : $this->fields['hourmax'];
             if ($deb < $fin && $h < $deb) {
                 $disp = date('Y-m-d', $next) . " {$deb}:00:00";
                 $next = strtotime($disp);
             } else {
                 if ($deb < $fin && $h >= $this->fields['hourmax']) {
                     $disp = date('Y-m-d', $next + DAY_TIMESTAMP) . " {$deb}:00:00";
                     $next = strtotime($disp);
                 }
             }
             if ($deb > $fin && $h < $deb && $h >= $fin) {
                 $disp = date('Y-m-d', $next) . " {$deb}:00:00";
                 $next = strtotime($disp);
             } else {
                 $disp = date("Y-m-d H:i:s", $next);
             }
             if ($next < time()) {
                 echo __('As soon as possible') . '<br>(' . Html::convDateTime($disp) . ') ';
             } else {
                 echo Html::convDateTime($disp);
             }
         }
     }
     if ($launch) {
         echo "&nbsp;";
         Html::showSimpleForm(static::getFormURL(), array('execute' => $this->fields['name']), __('Execute'));
     }
     if ($tmpstate == self::STATE_RUNNING) {
         Html::showSimpleForm(static::getFormURL(), 'resetstate', __('Blank'), array('id' => $ID), $CFG_GLPI['root_doc'] . "/pics/reset.png");
     }
     echo "</td></tr>";
     $this->showFormButtons($options);
     return true;
 }
Example #2
0
 /**
  * Generic Function to add default where to a request
  *
  * @param $itemtype device type
  *
  * @return select string
  **/
 static function addDefaultWhere($itemtype)
 {
     global $CFG_GLPI;
     switch ($itemtype) {
         case 'Reminder':
             return Reminder::addVisibilityRestrict();
         case 'RSSFeed':
             return RSSFeed::addVisibilityRestrict();
         case 'Notification':
             if (!Config::canView()) {
                 return " `glpi_notifications`.`itemtype` NOT IN ('Crontask', 'DBConnection') ";
             }
             break;
             // No link
         // No link
         case 'User':
             // View all entities
             if (Session::isViewAllEntities()) {
                 return "";
             }
             return getEntitiesRestrictRequest("", "glpi_profiles_users");
         case 'ProjectTask':
             $condition = '';
             $teamtable = 'glpi_projecttaskteams';
             $condition .= "((`{$teamtable}`.`itemtype` = 'User'\n                             AND `{$teamtable}`.`items_id` = '" . Session::getLoginUserID() . "')";
             if (count($_SESSION['glpigroups'])) {
                 $condition .= " OR (`{$teamtable}`.`itemtype` = 'Group'\n                                    AND `{$teamtable}`.`items_id`\n                                       IN (" . implode(",", $_SESSION['glpigroups']) . "))";
             }
             $condition .= ") ";
             return $condition;
         case 'Project':
             $condition = '';
             if (!Session::haveRight("project", Project::READALL)) {
                 $teamtable = 'glpi_projectteams';
                 $condition .= "(`glpi_projects`.users_id = '" . Session::getLoginUserID() . "'\n                               OR (`{$teamtable}`.`itemtype` = 'User'\n                                   AND `{$teamtable}`.`items_id` = '" . Session::getLoginUserID() . "')";
                 if (count($_SESSION['glpigroups'])) {
                     $condition .= " OR (`glpi_projects`.`groups_id`\n                                       IN (" . implode(",", $_SESSION['glpigroups']) . "))";
                     $condition .= " OR (`{$teamtable}`.`itemtype` = 'Group'\n                                      AND `{$teamtable}`.`items_id`\n                                          IN (" . implode(",", $_SESSION['glpigroups']) . "))";
                 }
                 $condition .= ") ";
             }
             return $condition;
         case 'Ticket':
             // Same structure in addDefaultJoin
             $condition = '';
             if (!Session::haveRight("ticket", Ticket::READALL)) {
                 $searchopt =& self::getOptions($itemtype);
                 $requester_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[4]['joinparams']['beforejoin']['joinparams']) . '`';
                 $requestergroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[71]['joinparams']['beforejoin']['joinparams']) . '`';
                 $assign_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[5]['joinparams']['beforejoin']['joinparams']) . '`';
                 $assigngroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[8]['joinparams']['beforejoin']['joinparams']) . '`';
                 $observer_table = '`glpi_tickets_users_' . self::computeComplexJoinID($searchopt[66]['joinparams']['beforejoin']['joinparams']) . '`';
                 $observergroup_table = '`glpi_groups_tickets_' . self::computeComplexJoinID($searchopt[65]['joinparams']['beforejoin']['joinparams']) . '`';
                 $condition = "(";
                 if (Session::haveRight("ticket", Ticket::READMY)) {
                     $condition .= " {$requester_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR {$observer_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR `glpi_tickets`.`users_id_recipient` = '" . Session::getLoginUserID() . "'";
                 } else {
                     $condition .= "0=1";
                 }
                 if (Session::haveRight("ticket", Ticket::READGROUP)) {
                     if (count($_SESSION['glpigroups'])) {
                         $condition .= " OR {$requestergroup_table}.`groups_id`\n                                             IN (" . implode(",", $_SESSION['glpigroups']) . ")";
                         $condition .= " OR {$observergroup_table}.`groups_id`\n                                             IN (" . implode(",", $_SESSION['glpigroups']) . ")";
                     }
                 }
                 if (Session::haveRight("ticket", Ticket::OWN)) {
                     // Can own ticket : show assign to me
                     $condition .= " OR {$assign_table}.users_id = '" . Session::getLoginUserID() . "' ";
                 }
                 if (Session::haveRight("ticket", Ticket::READASSIGN)) {
                     // assign to me
                     $condition .= " OR {$assign_table}.`users_id` = '" . Session::getLoginUserID() . "'";
                     if (count($_SESSION['glpigroups'])) {
                         $condition .= " OR {$assigngroup_table}.`groups_id`\n                                             IN (" . implode(",", $_SESSION['glpigroups']) . ")";
                     }
                     if (Session::haveRight('ticket', Ticket::ASSIGN)) {
                         $condition .= " OR `glpi_tickets`.`status`='" . CommonITILObject::INCOMING . "'";
                     }
                 }
                 if (Session::haveRightsOr('ticketvalidation', array(TicketValidation::VALIDATEINCIDENT, TicketValidation::VALIDATEREQUEST))) {
                     $condition .= " OR `glpi_ticketvalidations`.`users_id_validate`\n                                          = '" . Session::getLoginUserID() . "'";
                 }
                 $condition .= ") ";
             }
             return $condition;
         case 'Change':
         case 'Problem':
             if ($itemtype == 'Change') {
                 $right = 'change';
                 $table = 'changes';
                 $groupetable = "`glpi_changes_groups_";
             } else {
                 if ($itemtype == 'Problem') {
                     $right = 'problem';
                     $table = 'problems';
                     $groupetable = "`glpi_groups_problems";
                 }
             }
             // Same structure in addDefaultJoin
             $condition = '';
             if (!Session::haveRight("{$right}", $itemtype::READALL)) {
                 $searchopt =& self::getOptions($itemtype);
                 if (Session::haveRight("{$right}", $itemtype::READMY)) {
                     $requester_table = '`glpi_' . $table . '_users_' . self::computeComplexJoinID($searchopt[4]['joinparams']['beforejoin']['joinparams']) . '`';
                     $requestergroup_table = $groupetable . self::computeComplexJoinID($searchopt[71]['joinparams']['beforejoin']['joinparams']) . '`';
                     $observer_table = '`glpi_' . $table . '_users_' . self::computeComplexJoinID($searchopt[66]['joinparams']['beforejoin']['joinparams']) . '`';
                     $observergroup_table = $groupetable . self::computeComplexJoinID($searchopt[65]['joinparams']['beforejoin']['joinparams']) . '`';
                     $assign_table = '`glpi_' . $table . '_users_' . self::computeComplexJoinID($searchopt[5]['joinparams']['beforejoin']['joinparams']) . '`';
                     $assigngroup_table = $groupetable . self::computeComplexJoinID($searchopt[8]['joinparams']['beforejoin']['joinparams']) . '`';
                 }
                 $condition = "(";
                 if (Session::haveRight("{$right}", $itemtype::READMY)) {
                     $condition .= " {$requester_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR {$observer_table}.users_id = '" . Session::getLoginUserID() . "'\n                                    OR `glpi_" . $table . "`.`users_id_recipient` = '" . Session::getLoginUserID() . "'";
                 } else {
                     $condition .= "0=1";
                 }
                 $condition .= ") ";
             }
             return $condition;
         default:
             // Plugin can override core definition for its type
             if ($plug = isPluginItemType($itemtype)) {
                 $function = 'plugin_' . $plug['plugin'] . '_addDefaultWhere';
                 if (function_exists($function)) {
                     $out = $function($itemtype);
                     if (!empty($out)) {
                         return $out;
                     }
                 }
             }
             return "";
     }
 }
 function canViewItem()
 {
     if (($this->fields['itemtype'] == 'Crontask' || $this->fields['itemtype'] == 'DBConnection') && !Config::canView()) {
         return false;
     }
     return Session::haveAccessToEntity($this->getEntityID(), $this->isRecursive());
 }