Go to the documentation of this file.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
00037 require_once "class.ilObject.php";
00038
00039 class ilContainer extends ilObject
00040 {
00047 function ilObjContainer($a_id = 0, $a_call_by_reference = true)
00048 {
00049 $this->ilObject($a_id, $a_call_by_reference);
00050 }
00051
00052 function createContainerDirectory()
00053 {
00054 $webspace_dir = ilUtil::getWebspaceDir();
00055 $cont_dir = $webspace_dir."/container_data";
00056 if (!is_dir($cont_dir))
00057 {
00058 ilUtil::makeDir($cont_dir);
00059 }
00060 $obj_dir = $cont_dir."/obj_".$this->getId();
00061 if (!is_dir($obj_dir))
00062 {
00063 ilUtil::makeDir($obj_dir);
00064 }
00065 }
00066
00067 function getContainerDirectory()
00068 {
00069 return $this->_getContainerDirectory($this->getId());
00070 }
00071
00072 function _getContainerDirectory($a_id)
00073 {
00074 return ilUtil::getWebspaceDir()."/container_data/obj_".$a_id;
00075 }
00076
00077 function getBigIconPath()
00078 {
00079 return ilContainer::_lookupIconPath($this->getId(), "big");
00080 }
00081
00082 function getSmallIconPath()
00083 {
00084 return ilContainer::_lookupIconPath($this->getId(), "small");
00085 }
00086
00087 function _lookupContainerSetting($a_id, $a_keyword)
00088 {
00089 global $ilDB;
00090
00091 $q = "SELECT * FROM container_settings WHERE ".
00092 " id = ".$ilDB->quote($a_id)." AND ".
00093 " keyword = ".$ilDB->quote($a_keyword);
00094 $set = $ilDB->query($q);
00095 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00096
00097 return $rec["value"];
00098 }
00099
00100 function _writeContainerSetting($a_id, $a_keyword, $a_value)
00101 {
00102 global $ilDB;
00103
00104 $q = "REPLACE INTO container_settings (id, keyword, value) VALUES".
00105 " (".$ilDB->quote($a_id).", ".
00106 $ilDB->quote($a_keyword).", ".
00107 $ilDB->quote($a_value).")";
00108
00109 $ilDB->query($q);
00110 }
00111
00118 function _lookupIconPath($a_id, $a_size)
00119 {
00120 $size = ($a_size == "small")
00121 ? "small"
00122 : "big";
00123
00124 if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
00125 {
00126 $cont_dir = ilContainer::_getContainerDirectory($a_id);
00127 $file_name = $cont_dir."/icon_".$a_size.".gif";
00128
00129 if (is_file($file_name))
00130 {
00131 return $file_name;
00132 }
00133 }
00134
00135 return "";
00136 }
00137
00141 function saveIcons($a_big_icon, $a_small_icon)
00142 {
00143 global $ilDB;
00144
00145 $this->createContainerDirectory();
00146 $cont_dir = $this->getContainerDirectory();
00147
00148
00149 $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
00150 $this->ilias->getSetting("custom_icon_big_height");
00151 $big_file_name = $cont_dir."/icon_big.gif";
00152 if (is_file($a_big_icon["tmp_name"]))
00153 {
00154 $a_big_icon["tmp_name"] = ilUtil::escapeShellArg($a_big_icon["tmp_name"]);
00155 $big_file_name = ilUtil::escapeShellArg($big_file_name);
00156 $cmd = ilUtil::getConvertCmd()." ".$a_big_icon["tmp_name"]."[0] -geometry $big_geom GIF:$big_file_name";
00157 system($cmd);
00158 }
00159
00160 if (is_file($cont_dir."/icon_big.gif"))
00161 {
00162 ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
00163 }
00164 else
00165 {
00166 ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
00167 }
00168
00169
00170 $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
00171 $this->ilias->getSetting("custom_icon_small_height");
00172 $small_file_name = $cont_dir."/icon_small.gif";
00173
00174 if (is_file($a_small_icon["tmp_name"]))
00175 {
00176 $a_small_icon["tmp_name"] = ilUtil::escapeShellArg($a_small_icon["tmp_name"]);
00177 $small_file_name = ilUtil::escapeShellArg($small_file_name);
00178 $cmd = ilUtil::getConvertCmd()." ".$a_small_icon["tmp_name"]."[0] -geometry $small_geom GIF:$small_file_name";
00179 system($cmd);
00180 }
00181 if (is_file($cont_dir."/icon_small.gif"))
00182 {
00183 ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
00184 }
00185 else
00186 {
00187 ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
00188 }
00189
00190 }
00191
00195 function removeBigIcon()
00196 {
00197 $cont_dir = $this->getContainerDirectory();
00198 $big_file_name = $cont_dir."/icon_big.gif";
00199 @unlink($big_file_name);
00200 ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
00201 }
00202
00206 function removeSmallIcon()
00207 {
00208 $cont_dir = $this->getContainerDirectory();
00209 $small_file_name = $cont_dir."/icon_small.gif";
00210 @unlink($small_file_name);
00211 ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
00212 }
00213
00214 }
00215 ?>