/**
  * Lookup usages of media object
  *
  * @todo: This should be all in one context -> mob id table
  */
 function lookupUsages($a_id, $a_include_history = true)
 {
     global $ilDB;
     $hist_str = "";
     if ($a_include_history) {
         $hist_str = ", usage_hist_nr";
     }
     // get usages in pages
     $q = "SELECT DISTINCT usage_type, usage_id, usage_lang" . $hist_str . " FROM mob_usage WHERE id = " . $ilDB->quote($a_id, "integer");
     if (!$a_include_history) {
         $q .= " AND usage_hist_nr = " . $ilDB->quote(0, "integer");
     }
     $us_set = $ilDB->query($q);
     $ret = array();
     while ($us_rec = $ilDB->fetchAssoc($us_set)) {
         $ut = "";
         if (is_int(strpos($us_rec["usage_type"], ":"))) {
             $us_arr = explode(":", $us_rec["usage_type"]);
             $ut = $us_arr[1];
             $ct = $us_arr[0];
         }
         // check whether page exists
         $skip = false;
         if ($ut == "pg") {
             include_once "./Services/COPage/classes/class.ilPageObject.php";
             if (!ilPageObject::_exists($ct, $us_rec["usage_id"])) {
                 $skip = true;
             }
         }
         if (!$skip) {
             $ret[] = array("type" => $us_rec["usage_type"], "id" => $us_rec["usage_id"], "lang" => $us_rec["usage_lang"], "hist_nr" => $us_rec["usage_hist_nr"]);
         }
     }
     // get usages in media pools
     $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.foreign_id = " . $ilDB->quote($a_id, "integer") . " AND mep_item.type = " . $ilDB->quote("mob", "text");
     $us_set = $ilDB->query($q);
     while ($us_rec = $ilDB->fetchAssoc($us_set)) {
         $ret[] = array("type" => "mep", "id" => $us_rec["mep_id"]);
     }
     // get usages in news items (media casts)
     include_once "./Services/News/classes/class.ilNewsItem.php";
     $news_usages = ilNewsItem::_lookupMediaObjectUsages($a_id);
     foreach ($news_usages as $nu) {
         $ret[] = $nu;
     }
     // get usages in map areas
     $q = "SELECT DISTINCT mob_id FROM media_item it, map_area area " . " WHERE area.item_id = it.id " . " AND area.link_type = " . $ilDB->quote("int", "text") . " " . " AND area.target = " . $ilDB->quote("il__mob_" . $a_id, "text");
     $us_set = $ilDB->query($q);
     while ($us_rec = $ilDB->fetchAssoc($us_set)) {
         $ret[] = array("type" => "map", "id" => $us_rec["mob_id"]);
     }
     // get usages in personal clipboards
     $users = ilObjUser::_getUsersForClipboadObject("mob", $a_id);
     foreach ($users as $user) {
         $ret[] = array("type" => "clip", "id" => $user);
     }
     return $ret;
 }