/**
  *  Generate ical file content
  *
  * @param $who user ID
  * @param $who_group group ID
  *
  * @return icalendar string
  **/
 static function generateIcal($who, $who_group)
 {
     global $CFG_GLPI, $LANG;
     if ($who == 0 && $who_group == 0) {
         return false;
     }
     include_once GLPI_ROOT . "/lib/icalcreator/iCalcreator.class.php";
     $v = new vcalendar();
     if (!empty($CFG_GLPI["version"])) {
         $v->setConfig('unique_id', "GLPI-Planning-" . trim($CFG_GLPI["version"]));
     } else {
         $v->setConfig('unique_id', "GLPI-Planning-UnknownVersion");
     }
     $v->setConfig('filename', "glpi.ics");
     $v->setProperty("method", "PUBLISH");
     $v->setProperty("version", "2.0");
     $v->setProperty("x-wr-calname", "GLPI-" . $who . "-" . $who_group);
     $v->setProperty("calscale", "GREGORIAN");
     $interv = array();
     $begin = time() - MONTH_TIMESTAMP * 12;
     $end = time() + MONTH_TIMESTAMP * 12;
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     // ---------------Tracking
     $interv = TicketPlanning::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     // ---------------Reminder
     $data = Reminder::populatePlanning(array('who' => $who, 'who_group' => $who_group, 'begin' => $begin, 'end' => $end));
     $interv = array_merge($interv, $data);
     // ---------------Plugin
     $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group));
     if (isset($data["items"]) && count($data["items"])) {
         $interv = array_merge($data["items"], $interv);
     }
     if (count($interv) > 0) {
         foreach ($interv as $key => $val) {
             $vevent = new vevent();
             //initiate EVENT
             if (isset($val["tickettasks_id"])) {
                 $vevent->setProperty("uid", "Job#" . $val["tickettasks_id"]);
             } else {
                 if (isset($val["reminders_id"])) {
                     $vevent->setProperty("uid", "Event#" . $val["reminders_id"]);
                 } else {
                     if (isset($val['planningID'])) {
                         // Specify the ID (for plugins)
                         $vevent->setProperty("uid", "Plugin#" . $val['planningID']);
                     } else {
                         $vevent->setProperty("uid", "Plugin#" . $key);
                     }
                 }
             }
             $vevent->setProperty("dstamp", $val["begin"]);
             $vevent->setProperty("dtstart", $val["begin"]);
             $vevent->setProperty("dtend", $val["end"]);
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("summary", $LANG['planning'][8] . " # " . $val["tickets_id"] . " " . $LANG['document'][14] . " # " . $val["device"]);
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("summary", $val["name"]);
                 }
             }
             if (isset($val["content"])) {
                 $vevent->setProperty("description", html_clean($val["content"]));
             } else {
                 if (isset($val["name"])) {
                     $vevent->setProperty("description", $val["name"]);
                 }
             }
             if (isset($val["tickets_id"])) {
                 $vevent->setProperty("url", $CFG_GLPI["url_base"] . "/index.php?redirect=tracking_" . $val["tickets_id"]);
             }
             $v->setComponent($vevent);
         }
     }
     $v->sort();
     //$v->parse();
     return $v->returnCalendar();
 }
Example #2
0
 public function show($when, $type, $who, $who_group)
 {
     global $LANG, $CFG_GLPI, $DB;
     // if (!haveRight("show_planning",READ) && !haveRight("show_all_planning",UPDATE)) {
     if (!haveRight("planning", CREATE) || !haveRight("planning", Ticket::READALL)) {
         return false;
     }
     // Define some constants
     $date = explode("-", $when);
     $time = mktime(0, 0, 0, $date[1], $date[2], $date[0]);
     // Check bisextile years
     list($current_year, $current_month, $current_day) = explode("-", $when);
     if ($current_year % 4 == 0) {
         $feb = 29;
     } else {
         $feb = 28;
     }
     $nb_days = array(31, $feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     // Begin of the month
     $begin_month_day = strftime("%w", mktime(0, 0, 0, $current_month, 1, $current_year));
     if ($begin_month_day == 0) {
         $begin_month_day = 7;
     }
     $end_month_day = strftime("%w", mktime(0, 0, 0, $current_month, $nb_days[$current_month - 1], $current_year));
     // Day of the week
     $dayofweek = date("w", $time);
     // Cas du dimanche
     if ($dayofweek == 0) {
         $dayofweek = 7;
     }
     // Get begin and duration
     $begin = 0;
     $end = 0;
     switch ($type) {
         case "month":
             $begin = strtotime($current_year . "-" . $current_month . "-01 00:00:00");
             $end = $begin + DAY_TIMESTAMP * $nb_days[$current_month - 1];
             $year_next = $date[0];
             $month_next = $date[1] + 1;
             if ($month_next > 12) {
                 $year_next++;
                 $month_next -= 12;
             }
             $year_prev = $date[0];
             $month_prev = $date[1] - 1;
             if ($month_prev == 0) {
                 $year_prev--;
                 $month_prev += 12;
             }
             $next = $year_next . "-" . sprintf("%02u", $month_next) . "-" . $date[2];
             $prev = $year_prev . "-" . sprintf("%02u", $month_prev) . "-" . $date[2];
             break;
         case "week":
             $tbegin = $begin = $time + mktime(0, 0, 0, 0, 1, 0) - mktime(0, 0, 0, 0, $dayofweek, 0);
             $end = $begin + WEEK_TIMESTAMP;
             break;
         case "day":
             $add = "";
             $begin = $time;
             $end = $begin + DAY_TIMESTAMP;
             break;
     }
     $begin = date("Y-m-d H:i:s", $begin);
     $end = date("Y-m-d H:i:s", $end);
     //construct navigation intervals
     if (in_array($type, array('week', 'day'))) {
         $time = strtotime($when);
         $step = 0;
         switch ($type) {
             case "week":
                 $step = WEEK_TIMESTAMP;
                 break;
             case "day":
                 $step = DAY_TIMESTAMP;
                 break;
         }
         $next = $time + $step + 10;
         $prev = $time - $step;
         $next = strftime("%Y-%m-%d", $next);
         $prev = strftime("%Y-%m-%d", $prev);
     }
     $navBar = self::showNavBar($next, $prev, $type, $who, $who_group);
     // Print Headers
     echo "<div class='center'><table class='tab_cadre_fixe mobile_calendar'>";
     // Print Headers
     echo "<tr class='tab_bg_1'>";
     switch ($type) {
         case "month":
             for ($i = 1; $i <= 7; $i++) {
                 echo "<th width='12%'>" . $LANG['calendarD'][$i % 7] . "</th>";
             }
             break;
         case "week":
             echo "<th />";
             for ($i = 1; $i <= 7; $i++, $tbegin += DAY_TIMESTAMP) {
                 echo "<th width='12%'>" . $LANG['calendarD'][$i % 7] . " " . date('d', $tbegin) . "</th>";
             }
             break;
         case "day":
             echo "<th />";
             echo "<th width='12%'>" . $LANG['calendarDay'][$dayofweek % 7] . " " . date('d', $tbegin) . "</th>";
             break;
     }
     echo "</tr>\n";
     // ---------------Tracking
     $interv = TicketPlanning::populatePlanning($who, $who_group, $begin, $end);
     // ---------------reminder
     $datareminders = Reminder::populatePlanning($who, $who_group, $begin, $end);
     $interv = array_merge($interv, $datareminders);
     // --------------- Plugins
     $data = doHookFunction("planning_populate", array("begin" => $begin, "end" => $end, "who" => $who, "who_group" => $who_group));
     if (isset($data["items"]) && count($data["items"])) {
         $interv = array_merge($data["items"], $interv);
     }
     // Display Items
     $tmp = explode(":", $CFG_GLPI["planning_begin"]);
     $hour_begin = $tmp[0];
     $tmp = explode(":", $CFG_GLPI["planning_end"]);
     $hour_end = $tmp[0];
     if ($tmp[1] > 0) {
         $hour_end++;
     }
     switch ($type) {
         case "week":
             for ($hour = $hour_begin; $hour <= $hour_end; $hour++) {
                 echo "<tr>";
                 echo "<td class='td_hour'>" . self::displayUsingTwoDigits($hour) . "</td>";
                 for ($i = 1; $i <= 7; $i++) {
                     echo "<td class='tab_bg_3 top' width='12%'>";
                     // From midnight
                     if ($hour == $hour_begin) {
                         $begin_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP);
                     } else {
                         $begin_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + $hour * HOUR_TIMESTAMP);
                     }
                     // To midnight
                     if ($hour == $hour_end) {
                         $end_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + 24 * HOUR_TIMESTAMP);
                     } else {
                         $end_time = date("Y-m-d H:i:s", strtotime($when) + ($i - $dayofweek) * DAY_TIMESTAMP + ($hour + 1) * HOUR_TIMESTAMP);
                     }
                     reset($interv);
                     while ($data = current($interv)) {
                         $type = "";
                         if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                             $type = "in";
                         } else {
                             if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                                 $type = "through";
                             } else {
                                 if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                     $type = "begin";
                                 } else {
                                     if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                         $type = "end";
                                     }
                                 }
                             }
                         }
                         if (empty($type)) {
                             next($interv);
                         } else {
                             self::displayPlanningItem($data, $who);
                             if ($type == "in") {
                                 unset($interv[key($interv)]);
                             } else {
                                 next($interv);
                             }
                         }
                     }
                     echo "</td>";
                 }
                 echo "</tr>\n";
             }
             break;
         case "day":
             for ($hour = $hour_begin; $hour <= $hour_end; $hour++) {
                 echo "<tr>";
                 $begin_time = date("Y-m-d H:i:s", strtotime($when) + $hour * HOUR_TIMESTAMP);
                 $end_time = date("Y-m-d H:i:s", strtotime($when) + ($hour + 1) * HOUR_TIMESTAMP);
                 echo "<td class='td_hour'>" . self::displayUsingTwoDigits($hour) . ":00</td>";
                 echo "<td class='tab_bg_3 top' width='12%'>";
                 reset($interv);
                 while ($data = current($interv)) {
                     $type = "";
                     if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                         $type = "in";
                     } else {
                         if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                             $type = "through";
                         } else {
                             if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                 $type = "begin";
                             } else {
                                 if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                     $type = "end";
                                 }
                             }
                         }
                     }
                     if (empty($type)) {
                         next($interv);
                     } else {
                         Planning::displayPlanningItem($data, $who, $type, 1);
                         if ($type == "in") {
                             unset($interv[key($interv)]);
                         } else {
                             next($interv);
                         }
                     }
                 }
                 echo "</td></tr>";
             }
             break;
         case "month":
             echo "<tr class='tab_bg_3'>";
             // Display first day out of the month
             for ($i = 1; $i < $begin_month_day; $i++) {
                 echo "<td style='background-color:#ffffff'>&nbsp;</td>";
             }
             // Print real days
             if ($current_month < 10 && strlen($current_month) == 1) {
                 $current_month = "0" . $current_month;
             }
             $begin_time = strtotime($begin);
             $end_time = strtotime($end);
             for ($time = $begin_time; $time < $end_time; $time += DAY_TIMESTAMP) {
                 // Add 6 hours for midnight problem
                 $day = date("d", $time + 6 * HOUR_TIMESTAMP);
                 echo "<td height='100' class='tab_bg_3 top'>";
                 echo "<table><tr><td style='text-align:left'>";
                 echo "<span class='month_day'>" . $day . "</span></td></tr>";
                 echo "<tr class='tab_bg_3 center'>";
                 echo "<td class='tab_bg_3 top' width='12%'>";
                 $begin_day = date("Y-m-d H:i:s", $time);
                 $end_day = date("Y-m-d H:i:s", $time + DAY_TIMESTAMP);
                 reset($interv);
                 while ($data = current($interv)) {
                     $type = "";
                     if ($data["begin"] >= $begin_day && $data["end"] <= $end_day) {
                         $type = "in";
                     } else {
                         if ($data["begin"] < $begin_day && $data["end"] > $end_day) {
                             $type = "through";
                         } else {
                             if ($data["begin"] >= $begin_day && $data["begin"] < $end_day) {
                                 $type = "begin";
                             } else {
                                 if ($data["end"] > $begin_day && $data["end"] <= $end_day) {
                                     $type = "end";
                                 }
                             }
                         }
                     }
                     if (empty($type)) {
                         next($interv);
                     } else {
                         self::displayPlanningItem($data, $who);
                         if ($type == "in") {
                             unset($interv[key($interv)]);
                         } else {
                             next($interv);
                         }
                     }
                 }
                 echo "</td></tr></table>";
                 echo "</td>";
                 // Add break line
                 if (($day + $begin_month_day) % 7 == 1) {
                     echo "</tr>\n";
                     if ($day != $nb_days[$current_month - 1]) {
                         echo "<tr>";
                     }
                 }
             }
             if ($end_month_day != 0) {
                 for ($i = 0; $i < 7 - $end_month_day; $i++) {
                     echo "<td style='background-color:#ffffff'>&nbsp;</td>";
                 }
             }
             echo "</tr>";
             break;
     }
     echo "</table></div>";
     echo $navBar;
 }
Example #3
0
 /**
  * Find a user in a LDAP and return is BaseDN
  * Based on GRR auth system
  *
  * @param $ldap_method : ldap_method array to use
  * @param $login User Login
  * @param $password User Password
  *
  * @return String : basedn of the user / false if not founded
  **/
 function connection_ldap($ldap_method, $login, $password)
 {
     global $LANG;
     // we prevent some delay...
     if (empty($ldap_method['host'])) {
         return false;
     }
     $this->ldap_connection = AuthLdap::tryToConnectToServer($ldap_method, $login, $password);
     $this->user_deleted_ldap = false;
     if ($this->ldap_connection) {
         $params['method'] = AuthLDAP::IDENTIFIER_LOGIN;
         $params['fields'][AuthLDAP::IDENTIFIER_LOGIN] = $ldap_method['login_field'];
         $infos = AuthLdap::searchUserDn($this->ldap_connection, array('basedn' => $ldap_method['basedn'], 'login_field' => $ldap_method['login_field'], 'search_parameters' => $params, 'user_params' => array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $login), 'condition' => $ldap_method['condition'], 'user_dn' => $this->user_dn));
         $dn = $infos['dn'];
         if (!empty($dn) && @ldap_bind($this->ldap_connection, $dn, $password)) {
             //Hook to implement to restrict access by checking the ldap directory
             if (doHookFunction("restrict_ldap_auth", $dn)) {
                 return $dn;
             } else {
                 $this->addToError($LANG['login'][11]);
                 //Use is present by has no right to connect because of a plugin
                 return false;
             }
         } else {
             // Incorrect login
             $this->addToError($LANG['login'][12]);
             //Use is not present anymore in the directory!
             if ($dn == '') {
                 $this->user_deleted_ldap = true;
             }
             return false;
         }
     } else {
         $this->addToError($LANG['ldap'][6]);
         //Directory is not available
         return false;
     }
 }
Example #4
0
 /**
  * Function that try to load from LDAP the user information...
  *
  * @param $ldap_connection ldap connection descriptor
  * @param $ldap_method LDAP method
  * @param $userdn Basedn of the user
  * @param $login User Login
  *
  * @return String : basedn of the user / false if not founded
  **/
 function getFromLDAP($ldap_connection, $ldap_method, $userdn, $login)
 {
     global $DB, $CFG_GLPI;
     // we prevent some delay...
     if (empty($ldap_method["host"])) {
         return false;
     }
     if ($ldap_connection) {
         //Set all the search fields
         $this->fields['password'] = "";
         $fields = AuthLDAP::getSyncFields($ldap_method);
         $fields = array_filter($fields);
         $f = array_values($fields);
         $sr = @ldap_read($ldap_connection, $userdn, "objectClass=*", $f);
         $v = ldap_get_entries_clean($ldap_connection, $sr);
         if (!is_array($v) || count($v) == 0 || empty($v[0][$fields['name']][0])) {
             return false;
         }
         //Store user's dn
         $this->fields['user_dn'] = addslashes($userdn);
         //Store date_sync
         $this->fields['date_sync'] = $_SESSION['glpi_currenttime'];
         foreach ($fields as $k => $e) {
             if (empty($v[0][$e][0])) {
                 switch ($k) {
                     case "language":
                         // Not set value : managed but user class
                         break;
                     case "usertitles_id":
                     case "usercategories_id":
                         $this->fields[$k] = 0;
                         break;
                     default:
                         $this->fields[$k] = "";
                 }
             } else {
                 switch ($k) {
                     case "language":
                         $language = Config::getLanguage($v[0][$e][0]);
                         if ($language != '') {
                             $this->fields[$k] = $language;
                         }
                         break;
                     case "usertitles_id":
                         $this->fields[$k] = Dropdown::importExternal('UserTitle', addslashes($v[0][$e][0]));
                         break;
                     case "usercategories_id":
                         $this->fields[$k] = Dropdown::importExternal('UserCategory', addslashes($v[0][$e][0]));
                         break;
                     default:
                         if (!empty($v[0][$e][0])) {
                             $this->fields[$k] = addslashes($v[0][$e][0]);
                         } else {
                             $this->fields[$k] = "";
                         }
                 }
             }
         }
         // Empty array to ensure than syncLdapGroups will be done
         $this->fields["_groups"] = array();
         ///The groups are retrieved by looking into an ldap user object
         if ($ldap_method["group_search_type"] == 0 || $ldap_method["group_search_type"] == 2) {
             $this->getFromLDAPGroupVirtual($ldap_connection, $ldap_method, $userdn, $login);
         }
         ///The groups are retrived by looking into an ldap group object
         if ($ldap_method["group_search_type"] == 1 || $ldap_method["group_search_type"] == 2) {
             $this->getFromLDAPGroupDiscret($ldap_connection, $ldap_method, $userdn, $login);
         }
         ///Only process rules if working on the master database
         if (!$DB->isSlave()) {
             //Instanciate the affectation's rule
             $rule = new RuleRightCollection();
             //Process affectation rules :
             //we don't care about the function's return because all
             //the datas are stored in session temporary
             if (isset($this->fields["_groups"])) {
                 $groups = $this->fields["_groups"];
             } else {
                 $groups = array();
             }
             $this->fields = $rule->processAllRules($groups, $this->fields, array('type' => 'LDAP', 'ldap_server' => $ldap_method["id"], 'connection' => $ldap_connection, 'userdn' => $userdn));
             $this->fields['_ruleright_process'] = true;
             //If rule  action is ignore import
             if (isset($this->fields["_stop_import"])) {
                 return false;
             }
             //or no rights found & do not import users with no rights
             if (!$CFG_GLPI["use_noright_users_add"]) {
                 $ok = false;
                 if (isset($this->fields["_ldap_rules"]) && count($this->fields["_ldap_rules"])) {
                     if (isset($this->fields["_ldap_rules"]["rules_entities_rights"]) && count($this->fields["_ldap_rules"]["rules_entities_rights"])) {
                         $ok = true;
                     }
                     if (!$ok) {
                         $entity_count = 0;
                         $right_count = 0;
                         if (Profile::getDefault()) {
                             $right_count++;
                         }
                         if (isset($this->fields["_ldap_rules"]["rules_entities"])) {
                             $entity_count += count($this->fields["_ldap_rules"]["rules_entities"]);
                         }
                         if (isset($this->input["_ldap_rules"]["rules_rights"])) {
                             $right_count += count($this->fields["_ldap_rules"]["rules_rights"]);
                         }
                         if ($entity_count && $right_count) {
                             $ok = true;
                         }
                     }
                 }
                 if (!$ok) {
                     $this->fields["_stop_import"] = true;
                     return false;
                 }
             }
             //Hook to retrieve more informations for ldap
             $this->fields = doHookFunction("retrieve_more_data_from_ldap", $this->fields);
         }
         return true;
     }
     return false;
 }