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("./Services/COPage/classes/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 global $ilDB;
00124
00125 $q = "SELECT max(nr) AS max_nr FROM map_area WHERE item_id=".
00126 $ilDB->quote($a_item_id);
00127 $max_set = $this->ilias->db->query($q);
00128 $max_rec = $max_set->fetchRow(DB_FETCHMODE_ASSOC);
00129
00130 return $max_rec["max_nr"];
00131 }
00132
00136 function read()
00137 {
00138 global $ilDB;
00139
00140 $q = "SELECT * FROM map_area WHERE item_id=".
00141 $ilDB->quote($this->getItemId()).
00142 " AND nr=".$ilDB->quote($this->getNr());
00143 $area_set = $this->ilias->db->query($q);
00144 $area_rec = $area_set->fetchRow(DB_FETCHMODE_ASSOC);
00145
00146 $this->setShape($area_rec["shape"]);
00147
00148 $this->setNr($area_rec["nr"]);
00149 $this->setCoords($area_rec["coords"]);
00150 $this->setLinkType($area_rec["link_type"]);
00151 $this->setTitle($area_rec["title"]);
00152 $this->setHref($area_rec["href"]);
00153 $this->setTarget($area_rec["target"]);
00154 $this->setType($area_rec["type"]);
00155 $this->setTargetFrame($area_rec["target_frame"]);
00156 }
00157
00161 function update()
00162 {
00163 global $ilDB;
00164
00165 $q = "UPDATE map_area SET shape = ".$ilDB->quote($this->getShape()).
00166 ", coords = ".$ilDB->quote($this->getCoords()).
00167 ", link_type = ".$ilDB->quote($this->getLinkType()).
00168 ", title = ".$ilDB->quote($this->getTitle()).
00169 ", href = ".$ilDB->quote($this->getHref()).
00170 ", target = ".$ilDB->quote($this->getTarget()).
00171 ", type = ".$ilDB->quote($this->getType()).
00172 ", target_frame = ".$ilDB->quote($this->getTargetFrame()).
00173 " WHERE item_id = ".$ilDB->quote($this->getItemId())." AND nr = ".
00174 $ilDB->quote($this->getNr());
00175 $this->ilias->db->query($q);
00176
00177 }
00178
00182 function _resolveIntLinks($a_item_id)
00183 {
00184 global $ilDB;
00185
00186
00187 $q = "SELECT * FROM map_area WHERE item_id=".$ilDB->quote($a_item_id);
00188 $area_set = $this->ilias->db->query($q);
00189 while ($area_rec = $area_set->fetchRow(DB_FETCHMODE_ASSOC))
00190 {
00191 $target = $area_rec["target"];
00192 $type = $area_rec["type"];
00193 $item_id = $area_rec["item_id"];
00194 $nr = $area_rec["nr"];
00195
00196 if (($area_rec["link_type"] == IL_INT_LINK) && (!is_int(strpos($target, "__"))))
00197 {
00198 $new_target = ilInternalLink::_getIdForImportId($type, $target);
00199 if ($new_target !== false)
00200 {
00201 $query = "UPDATE map_area SET target= ".$ilDB->quote($new_target)." ".
00202 "WHERE item_id= ".$ilDB->quote($item_id)." AND nr=".$ilDB->quote($nr);
00203 $this->ilias->db->query($query);
00204 }
00205 }
00206 }
00207 }
00208
00214 function _getIntLinks($a_item_id)
00215 {
00216 global $ilDB;
00217
00218 $q = "SELECT * FROM map_area WHERE item_id=".$ilDB->quote($a_item_id);
00219 $area_set = $this->ilias->db->query($q);
00220
00221 $links = array();
00222
00223 while ($area_rec = $area_set->fetchRow(DB_FETCHMODE_ASSOC))
00224 {
00225 $target = $area_rec["target"];
00226 $type = $area_rec["type"];
00227 $targetframe = $area_rec["target_frame"];
00228
00229 if (($area_rec["link_type"] == IL_INT_LINK) && (is_int(strpos($target, "__"))))
00230 {
00231 $links[$target.":".$type.":".$targetframe] =
00232 array("Target" => $target, "Type" => $type,
00233 "TargetFrame" => $targetframe);
00234 }
00235 }
00236 return $links;
00237 }
00238
00244 function setItemId($a_item_id)
00245 {
00246 $this->item_id = $a_item_id;
00247 }
00248
00254 function getItemId()
00255 {
00256 return $this->item_id;
00257 }
00258
00264 function setNr($a_nr)
00265 {
00266 $this->nr = $a_nr;
00267 }
00268
00274 function getNr()
00275 {
00276 return $this->nr;
00277 }
00278
00284 function setShape($a_shape)
00285 {
00286 $this->shape = $a_shape;
00287 }
00288
00294 function getShape()
00295 {
00296 return $this->shape;
00297 }
00298
00304 function setCoords($a_coords)
00305 {
00306 $this->coords = $a_coords;
00307 }
00308
00314 function getCoords()
00315 {
00316 return $this->coords;
00317 }
00318
00324 function setTitle($a_title)
00325 {
00326 $this->title = $a_title;
00327 }
00328
00334 function appendTitle($a_title_str)
00335 {
00336 $this->title.= $a_title_str;
00337 }
00338
00344 function getTitle()
00345 {
00346 return $this->title;
00347 }
00348
00354 function setLinkType($a_link_type)
00355 {
00356 $this->linktype = $a_link_type;
00357 }
00358
00364 function getLinkType()
00365 {
00366 return $this->linktype;
00367 }
00368
00374 function setHref($a_href)
00375 {
00376 $this->xl_href = $a_href;
00377 }
00378
00384 function getHref()
00385 {
00386 return $this->xl_href;
00387 }
00388
00394 function setExtTitle($a_title)
00395 {
00396 $this->xl_title = $a_title;
00397 }
00398
00404 function getExtTitle()
00405 {
00406 return $this->xl_title;
00407 }
00408
00414 function setTarget($a_target)
00415 {
00416 $this->il_target = $a_target;
00417 }
00418
00424 function getTarget($a_insert_inst = false)
00425 {
00426 $target = $this->il_target;
00427
00428 if ((substr($target, 0, 4) == "il__") && $a_insert_inst)
00429 {
00430 $target = "il_".IL_INST_ID."_".substr($target, 4, strlen($target) - 4);
00431 }
00432
00433 return $target;
00434 }
00435
00442 function setType($a_type)
00443 {
00444 $this->il_type = $a_type;
00445 }
00446
00452 function getType()
00453 {
00454 return $this->il_type;
00455 }
00456
00463 function setTargetFrame($a_target_frame)
00464 {
00465 $this->il_target_frame = $a_target_frame;
00466 }
00467
00474 function getTargetFrame()
00475 {
00476 return $this->il_target_frame;
00477 }
00478
00484 function draw(&$a_image, $a_col1, $a_col2, $a_close_poly = true,
00485 $a_x_ratio = 1, $a_y_ratio = 1)
00486 {
00487 switch ($this->getShape())
00488 {
00489 case "Rect" :
00490 $this->drawRect($a_image, $this->getCoords(), $a_col1, $a_col2,
00491 $a_x_ratio, $a_y_ratio);
00492 break;
00493
00494 case "Circle" :
00495 $this->drawCircle($a_image, $this->getCoords(), $a_col1, $a_col2,
00496 $a_x_ratio, $a_y_ratio);
00497 break;
00498
00499 case "Poly" :
00500 $this->drawPoly($a_image, $this->getCoords(), $a_col1, $a_col2, $a_close_poly,
00501 $a_x_ratio, $a_y_ratio);
00502 break;
00503 }
00504 }
00505
00517 function drawLine(&$im, $x1, $y1, $x2, $y2, $c1, $c2)
00518 {
00519 imageline($im, $x1+1, $y1, $x2+1, $y2, $c1);
00520 imageline($im, $x1-1, $y1, $x2-1, $y2, $c1);
00521 imageline($im, $x1, $y1+1, $x2, $y2+1, $c1);
00522 imageline($im, $x1, $y1-1, $x2, $y2-1, $c1);
00523 imageline($im, $x1, $y1, $x2, $y2, $c2);
00524 }
00525
00535 function drawRect(&$im,$coords,$c1,$c2,$a_x_ratio = 1, $a_y_ratio = 1)
00536 {
00537 $coord=explode(",", $coords);
00538
00539 $this->drawLine($im, $coord[0] / $a_x_ratio, $coord[1] / $a_y_ratio,
00540 $coord[0] / $a_x_ratio, $coord[3] / $a_y_ratio, $c1, $c2);
00541 $this->drawLine($im, $coord[0] / $a_x_ratio, $coord[3] / $a_y_ratio,
00542 $coord[2] / $a_x_ratio, $coord[3] / $a_y_ratio, $c1, $c2);
00543 $this->drawLine($im, $coord[2] / $a_x_ratio, $coord[3] / $a_y_ratio,
00544 $coord[2] / $a_x_ratio, $coord[1] / $a_y_ratio, $c1, $c2);
00545 $this->drawLine($im, $coord[2] / $a_x_ratio, $coord[1] / $a_y_ratio,
00546 $coord[0] / $a_x_ratio, $coord[1] / $a_y_ratio, $c1, $c2);
00547 }
00548
00549
00560 function drawPoly(&$im, $coords, $c1, $c2, $closed,$a_x_ratio = 1, $a_y_ratio = 1)
00561 {
00562 if ($closed)
00563 {
00564 $p = 0;
00565 }
00566 else
00567 {
00568 $p = 1;
00569 }
00570
00571 $anz = ilMapArea::countCoords($coords);
00572
00573 if ($anz < (3 - $p))
00574 {
00575 return;
00576 }
00577
00578 $c = explode(",", $coords);
00579
00580 for($i=0; $i<$anz-$p; $i++)
00581 {
00582 $this->drawLine($im, $c[$i*2] / $a_x_ratio, $c[$i*2+1] / $a_y_ratio,
00583 $c[($i*2+2)%(2*$anz)] / $a_x_ratio,
00584 $c[($i*2+3)%(2*$anz)] / $a_y_ratio, $c1, $c2);
00585 }
00586 }
00587
00588
00598 function drawCircle(&$im, $coords, $c1, $c2,$a_x_ratio = 1, $a_y_ratio = 1)
00599 {
00600 $c = explode(",", $coords);
00601 imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
00602 ($c[2]+1)*2 / $a_x_ratio, ($c[2]+1)*2 / $a_y_ratio, 1, 360, $c1);
00603 imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
00604 ($c[2]-1)*2 / $a_x_ratio, ($c[2]-1)*2 / $a_y_ratio, 1, 360, $c1);
00605 imagearc($im, $c[0] / $a_x_ratio, $c[1] / $a_y_ratio,
00606 $c[2]*2 / $a_x_ratio, $c[2]*2 / $a_y_ratio, 1, 360, $c2);
00607 }
00608
00614 function countCoords($c)
00615 {
00616 if ($c == "")
00617 {
00618 return 0;
00619 }
00620 else
00621 {
00622 $coord_array = explode(",", $c);
00623 return (count($coord_array) / 2);
00624 }
00625 }
00626
00627 }
00628 ?>