• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilContainer.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00036 require_once "class.ilObject.php";
00037 
00038 class ilContainer extends ilObject
00039 {
00046         function ilObjContainer($a_id = 0, $a_call_by_reference = true)
00047         {
00048                 $this->ilObject($a_id, $a_call_by_reference);
00049         }
00050         
00055         function createContainerDirectory()
00056         {
00057                 $webspace_dir = ilUtil::getWebspaceDir();
00058                 $cont_dir = $webspace_dir."/container_data";
00059                 if (!is_dir($cont_dir))
00060                 {
00061                         ilUtil::makeDir($cont_dir);
00062                 }
00063                 $obj_dir = $cont_dir."/obj_".$this->getId();
00064                 if (!is_dir($obj_dir))
00065                 {
00066                         ilUtil::makeDir($obj_dir);
00067                 }
00068         }
00069         
00075         function getContainerDirectory()
00076         {
00077                 return $this->_getContainerDirectory($this->getId());
00078         }
00079         
00085         function _getContainerDirectory($a_id)
00086         {
00087                 return ilUtil::getWebspaceDir()."/container_data/obj_".$a_id;
00088         }
00089         
00095         function getBigIconPath()
00096         {
00097                 return ilContainer::_lookupIconPath($this->getId(), "big");
00098         }
00099 
00105         function getSmallIconPath()
00106         {
00107                 return ilContainer::_lookupIconPath($this->getId(), "small");
00108         }
00109 
00115         function getTinyIconPath()
00116         {
00117                 return ilContainer::_lookupIconPath($this->getId(), "tiny");
00118         }
00119         
00128         function _lookupContainerSetting($a_id, $a_keyword)
00129         {
00130                 global $ilDB;
00131                 
00132                 $q = "SELECT * FROM container_settings WHERE ".
00133                                 " id = ".$ilDB->quote($a_id)." AND ".
00134                                 " keyword = ".$ilDB->quote($a_keyword);
00135                 $set = $ilDB->query($q);
00136                 $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
00137                 
00138                 return $rec["value"];
00139         }
00140 
00141         function _writeContainerSetting($a_id, $a_keyword, $a_value)
00142         {
00143                 global $ilDB;
00144                 
00145                 $q = "REPLACE INTO container_settings (id, keyword, value) VALUES".
00146                         " (".$ilDB->quote($a_id).", ".
00147                         $ilDB->quote($a_keyword).", ".
00148                         $ilDB->quote($a_value).")";
00149 
00150                 $ilDB->query($q);
00151         }
00152         
00159         function _lookupIconPath($a_id, $a_size = "big")
00160         {
00161                 if ($a_size == "")
00162                 {
00163                         $a_size = "big";
00164                 }
00165                 
00166                 $size = $a_size;
00167                 
00168                 if (ilContainer::_lookupContainerSetting($a_id, "icon_".$size))
00169                 {
00170                         $cont_dir = ilContainer::_getContainerDirectory($a_id);
00171                         $file_name = $cont_dir."/icon_".$a_size.".gif";
00172 
00173                         if (is_file($file_name))
00174                         {
00175                                 return $file_name;
00176                         }
00177                 }
00178                 
00179                 return "";
00180         }
00181 
00185         function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
00186         {
00187                 global $ilDB;
00188                 
00189                 $this->createContainerDirectory();
00190                 $cont_dir = $this->getContainerDirectory();
00191                 
00192                 // save big icon
00193                 $big_geom = $this->ilias->getSetting("custom_icon_big_width")."x".
00194                         $this->ilias->getSetting("custom_icon_big_height");
00195                 $big_file_name = $cont_dir."/icon_big.gif";
00196 
00197                 if (is_file($a_big_icon["tmp_name"]))
00198                 {
00199                         $a_big_icon["tmp_name"] = ilUtil::escapeShellArg($a_big_icon["tmp_name"]);
00200                         $big_file_name = ilUtil::escapeShellArg($big_file_name);
00201                         $cmd = ilUtil::getConvertCmd()." ".$a_big_icon["tmp_name"]."[0] -geometry $big_geom GIF:$big_file_name";
00202                         system($cmd);
00203                 }
00204 
00205                 if (is_file($cont_dir."/icon_big.gif"))
00206                 {
00207                         ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
00208                 }
00209                 else
00210                 {
00211                         ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
00212                 }
00213         
00214                 // save small icon
00215                 $small_geom = $this->ilias->getSetting("custom_icon_small_width")."x".
00216                         $this->ilias->getSetting("custom_icon_small_height");
00217                 $small_file_name = $cont_dir."/icon_small.gif";
00218 
00219                 if (is_file($a_small_icon["tmp_name"]))
00220                 {
00221                         $a_small_icon["tmp_name"] = ilUtil::escapeShellArg($a_small_icon["tmp_name"]);
00222                         $small_file_name = ilUtil::escapeShellArg($small_file_name);
00223                         $cmd = ilUtil::getConvertCmd()." ".$a_small_icon["tmp_name"]."[0] -geometry $small_geom GIF:$small_file_name";
00224                         system($cmd);
00225                 }
00226                 if (is_file($cont_dir."/icon_small.gif"))
00227                 {
00228                         ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
00229                 }
00230                 else
00231                 {
00232                         ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
00233                 }
00234 
00235                 // save tiny icon
00236                 $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width")."x".
00237                         $this->ilias->getSetting("custom_icon_tiny_height");
00238                 $tiny_file_name = $cont_dir."/icon_tiny.gif";
00239 
00240                 if (is_file($a_tiny_icon["tmp_name"]))
00241                 {
00242                         $a_tiny_icon["tmp_name"] = ilUtil::escapeShellArg($a_tiny_icon["tmp_name"]);
00243                         $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
00244                         $cmd = ilUtil::getConvertCmd()." ".$a_tiny_icon["tmp_name"]."[0] -geometry $tiny_geom GIF:$tiny_file_name";
00245                         system($cmd);
00246                 }
00247                 if (is_file($cont_dir."/icon_tiny.gif"))
00248                 {
00249                         ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
00250                 }
00251                 else
00252                 {
00253                         ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
00254                 }
00255 
00256         }
00257 
00261         function removeBigIcon()
00262         {
00263                 $cont_dir = $this->getContainerDirectory();
00264                 $big_file_name = $cont_dir."/icon_big.gif";
00265                 @unlink($big_file_name);
00266                 ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
00267         }
00268         
00272         function removeSmallIcon()
00273         {
00274                 $cont_dir = $this->getContainerDirectory();
00275                 $small_file_name = $cont_dir."/icon_small.gif";
00276                 @unlink($small_file_name);
00277                 ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
00278         }
00279         
00283         function removeTinyIcon()
00284         {
00285                 $cont_dir = $this->getContainerDirectory();
00286                 $tiny_file_name = $cont_dir."/icon_tiny.gif";
00287                 @unlink($tiny_file_name);
00288                 ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
00289         }
00290         
00296         function getFirstColumn()
00297         {
00298                 $col_id = ilContainer::_lookupContainerSetting($this->getId(), "first_column");
00299                 if ($col_id > 0)
00300                 {
00301                         include_once("./Services/Blocks/class.ilBlockColumn.php");
00302                         $block_column = new ilBlockColumn($col_id);
00303                         return $block_column;
00304                 }
00305                 return false;
00306         }
00307         
00308 
00320         public function cloneAllObject($session_id, $client_id, $new_type, $ref_id, $clone_source, $options)
00321         {
00322                 global $ilLog;
00323                 
00324                 include_once('classes/class.ilLink.php');
00325                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
00326                 
00327                 global $ilAccess,$ilErr,$rbacsystem,$tree,$ilUser;
00328                         
00329                 // Save wizard options
00330                 $copy_id = ilCopyWizardOptions::_allocateCopyId();
00331                 $wizard_options = ilCopyWizardOptions::_getInstance($copy_id);
00332                 $wizard_options->saveOwner($ilUser->getId());
00333                 $wizard_options->saveRoot($clone_source);
00334                         
00335                 // add entry for source container
00336                 $wizard_options->initContainer($clone_source, $ref_id);
00337                 
00338                 foreach($options as $source_id => $option)
00339                 {
00340                         $wizard_options->addEntry($source_id,$option);
00341                 }
00342                 $wizard_options->read();
00343                 $wizard_options->storeTree($clone_source);
00344                 
00345                 // Duplicate session to avoid logout problems with backgrounded SOAP calls
00346                 $new_session_id = duplicate_session($session_id); 
00347                 
00348                 // Start cloning process using soap call
00349                 include_once 'Services/WebServices/SOAP/classes/class.ilSoapClient.php';
00350 
00351                 $soap_client = new ilSoapClient();
00352                 $soap_client->setTimeout(30);
00353                 $soap_client->setResponseTimeout(30);
00354                 $soap_client->enableWSDL(true);
00355 
00356                 $ilLog->write(__METHOD__.': Trying to call Soap client...');
00357                 if($soap_client->init())
00358                 {
00359                         $ilLog->write(__METHOD__.': Calling soap clone method...');
00360                         $res = $soap_client->call('ilClone',array($new_session_id.'::'.$client_id, $copy_id));
00361                 }
00362                 else
00363                 {
00364                         $ilLog->write(__METHOD__.': SOAP call failed. Calling clone method manually. ');
00365                         $wizard_options->disableSOAP();
00366                         $wizard_options->read();                        
00367                         include_once('./webservice/soap/include/inc.soap_functions.php');
00368                         $res = ilClone($new_session_id.'::'.$client_id, $copy_id);
00369                 }
00370                                 
00371                 // Check if copy is in progress
00372                 if(ilCopyWizardOptions::_isFinished($copy_id))
00373                 {
00374                         return $res;
00375                 }
00376                 else
00377                 {
00378                         return $ref_id;
00379                 }       
00380         }
00381         
00382         
00383 } // END class.ilObjCategory
00384 ?>

Generated on Fri Dec 13 2013 17:56:47 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1