Reminder::addVisibilityRestrict PHP Method

addVisibilityRestrict() static public method

Return visibility SQL restriction to add
static public addVisibilityRestrict ( ) : string
return string restrict to add
    static function addVisibilityRestrict()
    {
        $restrict = "`glpi_reminders`.`users_id` = '" . Session::getLoginUserID() . "' ";
        if (!Session::haveRight(self::$rightname, READ)) {
            return $restrict;
        }
        // Users
        $restrict .= " OR `glpi_reminders_users`.`users_id` = '" . Session::getLoginUserID() . "' ";
        // Groups
        if (isset($_SESSION["glpigroups"]) && count($_SESSION["glpigroups"])) {
            $restrict .= " OR (`glpi_groups_reminders`.`groups_id`\n                                 IN ('" . implode("','", $_SESSION["glpigroups"]) . "')\n                            AND (`glpi_groups_reminders`.`entities_id` < 0\n                                 " . getEntitiesRestrictRequest("OR", "glpi_groups_reminders", '', '', true) . ")) ";
        }
        // Profiles
        if (isset($_SESSION["glpiactiveprofile"]) && isset($_SESSION["glpiactiveprofile"]['id'])) {
            $restrict .= " OR (`glpi_profiles_reminders`.`profiles_id`\n                                 = '" . $_SESSION["glpiactiveprofile"]['id'] . "'\n                            AND (`glpi_profiles_reminders`.`entities_id` < 0\n                                 " . getEntitiesRestrictRequest("OR", "glpi_profiles_reminders", '', '', true) . ")) ";
        }
        // Entities
        if (isset($_SESSION["glpiactiveentities"]) && count($_SESSION["glpiactiveentities"])) {
            // Force complete SQL not summary when access to all entities
            $restrict .= getEntitiesRestrictRequest("OR", "glpi_entities_reminders", '', '', true, true);
        }
        return '(' . $restrict . ')';
    }

Usage Example

 /**
  * Check is the curent user is allowed to see the file
  *
  * @param $options array of options (only 'tickets_id' used)
  *
  * @return boolean
  **/
 function canViewFile($options)
 {
     global $DB, $CFG_GLPI;
     if (isset($_SESSION["glpiactiveprofile"]["interface"]) && $_SESSION["glpiactiveprofile"]["interface"] == "central") {
         // My doc Check and Common doc right access
         if ($this->can($this->fields["id"], READ) || $this->fields["users_id"] === Session::getLoginUserID()) {
             return true;
         }
         // Reminder Case
         $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_reminders`\n                        ON (`glpi_reminders`.`id` = `glpi_documents_items`.`items_id`\n                            AND `glpi_documents_items`.`itemtype` = 'Reminder')\n                   " . Reminder::addVisibilityJoins() . "\n                   WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND " . Reminder::addVisibilityRestrict();
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             return true;
         }
         // Knowbase Case
         if (Session::haveRight("knowbase", READ)) {
             $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`\n                               AND `glpi_documents_items`.`itemtype` = 'KnowbaseItem')\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND " . KnowbaseItem::addVisibilityRestrict();
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
         }
         if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) {
             $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`\n                               AND `glpi_documents_items`.`itemtype` = 'KnowbaseItem')\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND `glpi_knowbaseitems`.`is_faq` = '1'\n                            AND " . KnowbaseItem::addVisibilityRestrict();
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
         }
         // Tracking Case
         if (isset($options["tickets_id"])) {
             $job = new Ticket();
             if ($job->can($options["tickets_id"], READ)) {
                 $query = "SELECT *\n                         FROM `glpi_documents_items`\n                         WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n                               AND `glpi_documents_items`.`itemtype` = 'Ticket'\n                               AND `documents_id`='" . $this->fields["id"] . "'";
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     return true;
                 }
             }
         }
     } else {
         if (Session::getLoginUserID()) {
             // ! central
             // Check if it is my doc
             if ($this->fields["users_id"] === Session::getLoginUserID()) {
                 return true;
             }
             // Reminder Case
             $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_reminders`\n                        ON (`glpi_reminders`.`id` = `glpi_documents_items`.`items_id`\n                            AND `glpi_documents_items`.`itemtype` = 'Reminder')\n                   " . Reminder::addVisibilityJoins() . "\n                   WHERE `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND " . Reminder::addVisibilityRestrict();
             $result = $DB->query($query);
             if ($DB->numrows($result) > 0) {
                 return true;
             }
             if (Session::haveRight('knowbase', KnowbaseItem::READFAQ)) {
                 // Check if it is a FAQ document
                 $query = "SELECT *\n                      FROM `glpi_documents_items`\n                      LEFT JOIN `glpi_knowbaseitems`\n                           ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                      " . KnowbaseItem::addVisibilityJoins() . "\n                      WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                            AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                            AND `glpi_knowbaseitems`.`is_faq` = '1'\n                            AND " . KnowbaseItem::addVisibilityRestrict();
                 $result = $DB->query($query);
                 if ($DB->numrows($result) > 0) {
                     return true;
                 }
             }
             // Tracking Case
             if (isset($options["tickets_id"])) {
                 $job = new Ticket();
                 if ($job->can($options["tickets_id"], READ)) {
                     $query = "SELECT *\n                         FROM `glpi_documents_items`\n                         WHERE `glpi_documents_items`.`items_id` = '" . $options["tickets_id"] . "'\n                               AND `glpi_documents_items`.`itemtype` = 'Ticket'\n                               AND `documents_id` = '" . $this->fields["id"] . "'";
                     $result = $DB->query($query);
                     if ($DB->numrows($result) > 0) {
                         return true;
                     }
                 }
             }
         }
     }
     // Public FAQ for not connected user
     if ($CFG_GLPI["use_public_faq"]) {
         $query = "SELECT *\n                   FROM `glpi_documents_items`\n                   LEFT JOIN `glpi_knowbaseitems`\n                        ON (`glpi_knowbaseitems`.`id` = `glpi_documents_items`.`items_id`)\n                   LEFT JOIN `glpi_entities_knowbaseitems`\n                        ON (`glpi_knowbaseitems`.`id` = `glpi_entities_knowbaseitems`.`knowbaseitems_id`)\n                   WHERE `glpi_documents_items`.`itemtype` = 'KnowbaseItem'\n                         AND `glpi_documents_items`.`documents_id` = '" . $this->fields["id"] . "'\n                         AND `glpi_knowbaseitems`.`is_faq` = '1'\n                         AND `glpi_entities_knowbaseitems`.`entities_id` = '0'\n                         AND `glpi_entities_knowbaseitems`.`is_recursive` = '1'";
         $result = $DB->query($query);
         if ($DB->numrows($result) > 0) {
             return true;
         }
     }
     return false;
 }
All Usage Examples Of Reminder::addVisibilityRestrict