Example #1
0
 /**
  * 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_avaibility (boolean)
  *
  * @return array of planning item
  **/
 static function populatePlanning($options = array())
 {
     global $DB, $CFG_GLPI;
     $default_options = array('color' => '', 'event_type_color' => '', 'check_planned' => false);
     $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 ($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;
     }
     if ($ASSIGN) {
         $query2 = "SELECT DISTINCT `glpi_reminders`.*\n                    FROM `glpi_reminders`\n                    {$joinstoadd}\n                    WHERE `glpi_reminders`.`is_planned` = '1'\n                          AND {$ASSIGN}\n                          {$PLANNED}\n                          AND `begin` < '{$end}'\n                          AND `end` > '{$begin}'\n                    ORDER BY `begin`";
         $result2 = $DB->query($query2);
         if ($DB->numrows($result2) > 0) {
             for ($i = 0; $data = $DB->fetch_assoc($result2); $i++) {
                 $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"];
                 $reminder->getFromDB($data["id"]);
                 $interv[$key]["editable"] = $reminder->canUpdateItem();
             }
         }
     }
     return $interv;
 }
Example #2
0
 /**
  * Populate the planning with planned project tasks
  *
  * @since version 0.85
  *
  * @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
  *
  * @return array of planning item
  **/
 static function populatePlanning($options = array())
 {
     global $DB, $CFG_GLPI;
     $interv = array();
     $ttask = new self();
     if (!isset($options['begin']) || $options['begin'] == 'NULL' || !isset($options['end']) || $options['end'] == 'NULL') {
         return $interv;
     }
     if (!isset($options['color'])) {
         $options['color'] = '';
     }
     if (!isset($options['event_type_color'])) {
         $options['event_type_color'] = '';
     }
     $who = $options['who'];
     $who_group = $options['who_group'];
     $begin = $options['begin'];
     $end = $options['end'];
     // Get items to print
     $ASSIGN = "";
     if ($who_group === "mine") {
         if (count($_SESSION["glpigroups"])) {
             $groups = implode("','", $_SESSION['glpigroups']);
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'Group'\n                       AND `glpi_projecttaskteams`.`items_id`\n                           IN (SELECT DISTINCT `groups_id`\n                               FROM `glpi_groups`\n                               WHERE `groups_id` IN ('{$groups}')\n                                     AND `glpi_groups`.`is_assign`)\n                                     AND ";
         } else {
             // Only personal ones
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'User'\n                       AND `glpi_projecttaskteams`.`items_id` = '{$who}'\n                       AND ";
         }
     } else {
         if ($who > 0) {
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'User'\n                       AND `glpi_projecttaskteams`.`items_id` = '{$who}'\n                       AND ";
         }
         if ($who_group > 0) {
             $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'Group'\n                       AND `glpi_projecttaskteams`.`items_id`\n                           IN ('{$who_group}')\n                       AND ";
         }
     }
     if (empty($ASSIGN)) {
         $ASSIGN = "`glpi_projecttaskteams`.`itemtype` = 'User'\n                       AND `glpi_projecttaskteams`.`items_id`\n                        IN (SELECT DISTINCT `glpi_profiles_users`.`users_id`\n                            FROM `glpi_profiles`\n                            LEFT JOIN `glpi_profiles_users`\n                                 ON (`glpi_profiles`.`id` = `glpi_profiles_users`.`profiles_id`)\n                            WHERE `glpi_profiles`.`interface` = 'central' " . getEntitiesRestrictRequest("AND", "glpi_profiles_users", '', $_SESSION["glpiactive_entity"], 1) . ")\n                     AND ";
     }
     $query = "SELECT `glpi_projecttasks`.*\n                FROM `glpi_projecttaskteams`\n                INNER JOIN `glpi_projecttasks`\n                  ON (`glpi_projecttasks`.`id` = `glpi_projecttaskteams`.`projecttasks_id`)\n                WHERE {$ASSIGN}\n                      '{$begin}' < `glpi_projecttasks`.`plan_end_date`\n                      AND '{$end}' > `glpi_projecttasks`.`plan_start_date`\n                ORDER BY `glpi_projecttasks`.`plan_start_date`";
     $result = $DB->query($query);
     $interv = array();
     $task = new self();
     if ($DB->numrows($result) > 0) {
         for ($i = 0; $data = $DB->fetch_assoc($result); $i++) {
             if ($task->getFromDB($data["id"])) {
                 $key = $data["plan_start_date"] . "\$\$\$" . "ProjectTask" . "\$\$\$" . $data["id"];
                 $interv[$key]['color'] = $options['color'];
                 $interv[$key]['event_type_color'] = $options['event_type_color'];
                 $interv[$key]['itemtype'] = 'ProjectTask';
                 $interv[$key]["url"] = $CFG_GLPI["root_doc"] . "/front/project.form.php?id=" . $task->fields['projects_id'];
                 $interv[$key]["ajaxurl"] = $CFG_GLPI["root_doc"] . "/ajax/planning.php" . "?action=edit_event_form" . "&itemtype=ProjectTask" . "&id=" . $data['id'] . "&url=" . $interv[$key]["url"];
                 $interv[$key][$task->getForeignKeyField()] = $data["id"];
                 $interv[$key]["id"] = $data["id"];
                 $interv[$key]["users_id"] = $data["users_id"];
                 if (strcmp($begin, $data["plan_start_date"]) > 0) {
                     $interv[$key]["begin"] = $begin;
                 } else {
                     $interv[$key]["begin"] = $data["plan_start_date"];
                 }
                 if (strcmp($end, $data["plan_end_date"]) < 0) {
                     $interv[$key]["end"] = $end;
                 } else {
                     $interv[$key]["end"] = $data["plan_end_date"];
                 }
                 $interv[$key]["name"] = $task->fields["name"];
                 $interv[$key]["content"] = Html::resume_text($task->fields["content"], $CFG_GLPI["cut"]);
                 $interv[$key]["status"] = $task->fields["percent_done"];
                 $ttask->getFromDB($data["id"]);
                 $interv[$key]["editable"] = $ttask->canUpdateItem();
             }
         }
     }
     return $interv;
 }