00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 require_once("content/classes/Pages/class.ilInternalLink.php");
00025
00026 define("IL_AREA_RECT", "Rect");
00027 define("IL_AREA_CIRCLE", "Circle");
00028 define("IL_AREA_POLY", "Poly");
00029
00030 define("IL_INT_LINK", "int");
00031 define("IL_EXT_LINK", "ext");
00032
00033 define("IL_LT_STRUCTURE", "StructureObject");
00034 define("IL_LT_PAGE", "PageObject");
00035 define("IL_LT_MEDIA", "MediaObject");
00036 define("IL_LT_GLITEM", "GlossaryItem");
00037
00038 define("IL_TF_MEDIA", "Media");
00039 define("IL_TF_FAQ", "FAQ");
00040 define("IL_TF_GLOSSARY", "Glossary");
00041 define("IL_TF_NEW", "New");
00042
00043
00054 class ilMapArea
00055 {
00056 var $ilias;
00057 var $item_id;
00058 var $nr;
00059 var $shape;
00060 var $coords;
00061 var $title;
00062 var $linktype;
00063 var $xl_title;
00064 var $xl_href;
00065 var $il_target;
00066 var $il_type;
00067 var $il_target_frame;
00068
00069
00076 function ilMapArea($a_item_id = 0, $a_nr = 0)
00077 {
00078 global $ilias;
00079
00080 $this->ilias =& $ilias;
00081 $this->title = "";
00082
00083 if ($a_item_id !=0 && $a_nr != 0)
00084 {
00085 $this->setItemId($a_item_id);
00086 $this->setNr($a_nr);
00087 $this->read();
00088 }
00089 }
00090
00094 function create()
00095 {
00096 global $ilDB;
00097
00098 $q = "INSERT INTO map_area (item_id, nr, shape, ".
00099 "coords, link_type, title, href, target, type, target_frame) ".
00100 " VALUES (".
00101 $ilDB->quote($this->getItemId()).",".
00102 $ilDB->quote($this->getNr()).",".
00103 $ilDB->quote($this->getShape()).",".
00104 $ilDB->quote($this->getCoords()).",".
00105 $ilDB->quote($this->getLinkType()).",".
00106 $ilDB->quote($this->getTitle()).",".
00107 $ilDB->quote($this->getHref()).",".
00108 $ilDB->quote($this->getTarget()).",".
00109 $ilDB->quote($this->getType()).",".
00110 $ilDB->quote($this->getTargetFrame()).")";
00111 $this->ilias->db->query($q);
00112 }
00113
00121 function _getMaxNr($a_item_id)
00122 {
00123 $q = "SELECT max(nr) AS max_nr FROM map_area WHERE item_id='".$a_item_id."'";
00124 $max_set = $this->ilias->db->query($q);
00125 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00126
00127 return $max_rec["max_nr"];
00128 }
00129
00133 function read()
00134 {
00135 $q = "SELECT * FROM map_area WHERE item_id='".$this->getItemId().
00136 "' AND nr='".$this->getNr()."'";
00137 $area_set = $this->ilias->db->query($q);
00138 $area_rec = $area_set->fetchRow(DB_FETCHMODE_ASSOC);
00139
00140 $this->setShape($area_rec["shape"]);
00141
00142 $this->setNr($area_rec["nr"]);
00143 $this->setCoords($area_rec["coords"]);
00144 $this->setLinkType($area_rec["link_type"]);
00145 $this->setTitle($area_rec["title"]);
00146 $this->setHref($area_rec["href"]);
00147 $this->setTarget($area_rec["target"]);
00148 $this->setType($area_rec["type"]);
00149 $this->setTargetFrame($area_rec["target_frame"]);
00150 }
00151
00155 function update()
00156 {
00157 global $ilDB;
00158
00159 $q = "UPDATE map_area SET shape = ".$ilDB->quote($this->getShape()).
00160 ", coords = ".$ilDB->quote($this->getCoords()).
00161 ", link_type = ".$ilDB->quote($this->getLinkType()).
00162 ", title = ".$ilDB->quote($this->getTitle()).
00163 ", href = ".$ilDB->quote($this->getHref()).
00164 ", target = ".$ilDB->quote($this->getTarget()).
00165 ", type = ".$ilDB->quote($this->getType()).
00166 ", target_frame = ".$ilDB->quote($this->getTargetFrame()).
00167 " WHERE item_id = ".$ilDB->quote($this->getItemId())." AND nr = ".
00168 $ilDB->quote($this->getNr());
00169 $this->ilias->db->query($q);
00170
00171 }
00172
00176 function _resolveIntLinks($a_item_id)
00177 {
00178 global $ilDB;
00179
00180
00181 $q = "SELECT * FROM map_area WHERE item_id='".$a_item_id."'";
00182 $area_set = $this->ilias->db->query($q);
00183 while ($area_rec = $area_set->fetchRow(DB_FETCHMODE_ASSOC))
00184 {
00185 $target = $area_rec["target"];
00186 $type = $area_rec["type"];
00187 $item_id = $area_rec["item_id"];
00188 $nr = $area_rec["nr"];
00189
00190 if (($area_rec["link_type"] == IL_INT_LINK) && (!is_int(strpos($target, "__"))))
00191 {
00192 $new_target = ilInternalLink::_getIdForImportId($type, $target);
00193 if ($new_target !== false)
00194 {
00195 $query = "UPDATE map_area SET target= ".$ilDB->quote($new_target)." ".
00196 "WHERE item_id= ".$ilDB->quote($item_id)." AND nr=".$ilDB->quote($nr);
00197 $this->ilias->db->query($query);
00198 }
00199 }
00200 }
00201 }
00202
00208 function _getIntLinks($a_item_id)
00209 {
00210 $q = "SELECT * FROM map_area WHERE item_id='".$a_item_id."'";
00211 $area_set = $this->ilias->db->query($q);
00212
00213 $links = array();
00214
00215 while ($area_rec = $area_set->fetchRow(DB_FETCHMODE_ASSOC))
00216 {
00217 $target = $area_rec["target"];
00218 $type = $area_rec["type"];
00219 $targetframe = $area_rec["target_frame"];
00220
00221 if (($area_rec["link_type"] == IL_INT_LINK) && (is_int(strpos($target, "__"))))
00222 {
00223 $links[$target.":".$type.":".$targetframe] =
00224 array("Target" => $target, "Type" => $type,
00225 "TargetFrame" => $targetframe);
00226 }
00227 }
00228 return $links;
00229 }
00230
00236 function setItemId($a_item_id)
00237 {
00238 $this->item_id = $a_item_id;
00239 }
00240
00246 function getItemId()
00247 {
00248 return $this->item_id;
00249 }
00250
00256 function setNr($a_nr)
00257 {
00258 $this->nr = $a_nr;
00259 }
00260
00266 function getNr()
00267 {
00268 return $this->nr;
00269 }
00270
00276 function setShape($a_shape)
00277 {
00278 $this->shape = $a_shape;
00279 }
00280
00286 function getShape()
00287 {
00288 return $this->shape;
00289 }
00290
00296 function setCoords($a_coords)
00297 {
00298 $this->coords = $a_coords;
00299 }
00300
00306 function getCoords()
00307 {
00308 return $this->coords;
00309 }
00310
00316 function setTitle($a_title)
00317 {
00318 $this->title = $a_title;
00319 }
00320
00326 function appendTitle($a_title_str)
00327 {
00328 $this->title.= $a_title_str;
00329 }
00330
00336 function getTitle()
00337 {
00338 return $this->title;
00339 }
00340
00346 function setLinkType($a_link_type)
00347 {
00348 $this->linktype = $a_link_type;
00349 }
00350
00356 function getLinkType()
00357 {
00358 return $this->linktype;
00359 }
00360
00366 function setHref($a_href)
00367 {
00368 $this->xl_href = $a_href;
00369 }
00370
00376 function getHref()
00377 {
00378 return $this->xl_href;
00379 }
00380
00386 function setExtTitle($a_title)
00387 {
00388 $this->xl_title = $a_title;
00389 }
00390
00396 function getExtTitle()
00397 {
00398 return $this->xl_title;
00399 }
00400
00406 function setTarget($a_target)
00407 {
00408 $this->il_target = $a_target;
00409 }
00410
00416 function getTarget($a_insert_inst = false)
00417 {
00418 $target = $this->il_target;
00419
00420 if ((substr($target, 0, 4) == "il__") && $a_insert_inst)
00421 {
00422 $target = "il_".IL_INST_ID."_".substr($target, 4, strlen($target) - 4);
00423 }
00424
00425 return $target;
00426 }
00427
00434 function setType($a_type)
00435 {
00436 $this->il_type = $a_type;
00437 }
00438
00444 function getType()
00445 {
00446 return $this->il_type;
00447 }
00448
00455 function setTargetFrame($a_target_frame)
00456 {
00457 $this->il_target_frame = $a_target_frame;
00458 }
00459
00466 function getTargetFrame()
00467 {
00468 return $this->il_target_frame;
00469 }
00470
00476 function draw(&$a_image, $a_col1, $a_col2, $a_close_poly = true)
00477 {
00478 switch ($this->getShape())
00479 {
00480 case "Rect" :
00481 $this->drawRect($a_image, $this->getCoords(), $a_col1, $a_col2);
00482 break;
00483
00484 case "Circle" :
00485 $this->drawCircle($a_image, $this->getCoords(), $a_col1, $a_col2);
00486 break;
00487
00488 case "Poly" :
00489 $this->drawPoly($a_image, $this->getCoords(), $a_col1, $a_col2, $a_close_poly);
00490 break;
00491 }
00492 }
00493
00505 function drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
00506 {
00507 imageline($im, $x1+1, $y1, $x2+1, $y2, $c1);
00508 imageline($im, $x1-1, $y1, $x2-1, $y2, $c1);
00509 imageline($im, $x1, $y1+1, $x2, $y2+1, $c1);
00510 imageline($im, $x1, $y1-1, $x2, $y2-1, $c1);
00511 imageline($im, $x1, $y1, $x2, $y2, $c2);
00512 }
00513
00523 function drawRect(&$im,$coords,$c1,$c2)
00524 {
00525 $coord=explode(",", $coords);
00526 $this->drawLine($im, $coord[0], $coord[1], $coord[0], $coord[3], $c1, $c2);
00527 $this->drawLine($im, $coord[0], $coord[3], $coord[2], $coord[3], $c1, $c2);
00528 $this->drawLine($im, $coord[2], $coord[3], $coord[2], $coord[1], $c1, $c2);
00529 $this->drawLine($im, $coord[2], $coord[1], $coord[0], $coord[1], $c1, $c2);
00530 }
00531
00532
00543 function drawPoly(&$im, $coords, $c1, $c2, $closed)
00544 {
00545 if ($closed)
00546 {
00547 $p = 0;
00548 }
00549 else
00550 {
00551 $p = 1;
00552 }
00553
00554 $anz = ilMapArea::countCoords($coords);
00555
00556 if ($anz < (3 - $p))
00557 {
00558 return;
00559 }
00560
00561 $c = explode(",", $coords);
00562
00563 for($i=0; $i<$anz-$p; $i++)
00564 {
00565 $this->drawLine($im, $c[$i*2], $c[$i*2+1], $c[($i*2+2)%(2*$anz)],
00566 $c[($i*2+3)%(2*$anz)], $c1, $c2);
00567 }
00568 }
00569
00570
00580 function drawCircle(&$im, $coords, $c1, $c2)
00581 {
00582 $c = explode(",", $coords);
00583 imagearc($im, $c[0], $c[1], ($c[2]+1)*2, ($c[2]+1)*2, 1, 360, $c1);
00584 imagearc($im, $c[0], $c[1], ($c[2]-1)*2, ($c[2]-1)*2, 1, 360, $c1);
00585 imagearc($im, $c[0], $c[1], $c[2]*2, $c[2]*2, 1, 360, $c2);
00586 }
00587
00593 function countCoords($c)
00594 {
00595 if ($c == "")
00596 {
00597 return 0;
00598 }
00599 else
00600 {
00601 $coord_array = explode(",", $c);
00602 return (count($coord_array) / 2);
00603 }
00604 }
00605
00606 }
00607 ?>