1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2008 ILIAS open source, University of Cologne | 7 | | 8 | This program is free software; you can redistribute it and/or | 9 | modify it under the terms of the GNU General Public License | 10 | as published by the Free Software Foundation; either version 2 | 11 | of the License, or (at your option) any later version. | 12 | | 13 | This program is distributed in the hope that it will be useful, | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | GNU General Public License for more details. | 17 | | 18 | You should have received a copy of the GNU General Public License | 19 | along with this program; if not, write to the Free Software | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 21 +-----------------------------------------------------------------------------+ 22*/ 23 24require_once "./Services/Object/classes/class.ilObject.php"; 25 26/** 27* Class ilObjCertificateSettings 28* 29* @author Helmut Schottmüller <ilias@aurealis.de> 30* @version $Id$ 31* 32* @ingroup ServicesCertificate 33*/ 34class ilObjCertificateSettings extends ilObject 35{ 36 37 /** 38 * Constructor 39 * @access public 40 * @param integer reference_id or object_id 41 * @param boolean treat the id as reference_id (true) or object_id (false) 42 */ 43 public function __construct($a_id = 0, $a_reference = true) 44 { 45 parent::__construct($a_id, $a_reference); 46 $this->type = "cert"; 47 } 48 49 public function hasBackgroundImage() 50 { 51 if (@file_exists($this->getBackgroundImagePath()) && (@filesize($this->getBackgroundImagePath()) > 0)) { 52 return true; 53 } else { 54 return false; 55 } 56 } 57 58 public function getBackgroundImageDefaultFolder() 59 { 60 return CLIENT_WEB_DIR . "/certificates/default/"; 61 } 62 63 /** 64 * Returns the filesystem path of the background image 65 * 66 * @return string The filesystem path of the background image 67 */ 68 public function getBackgroundImagePath() 69 { 70 return $this->getBackgroundImageDefaultFolder() . $this->getBackgroundImageName(); 71 } 72 73 /** 74 * Returns the filename of the background image 75 * 76 * @return string The filename of the background image 77 */ 78 public function getBackgroundImageName() 79 { 80 return "background.jpg"; 81 } 82 83 /** 84 * Returns the filesystem path of the background image thumbnail 85 * 86 * @return string The filesystem path of the background image thumbnail 87 */ 88 public function getBackgroundImageThumbPath() 89 { 90 return $this->getBackgroundImageDefaultFolder() . $this->getBackgroundImageName() . ".thumb.jpg"; 91 } 92 93 /** 94 * Returns the filesystem path of the background image temp file during upload 95 * 96 * @return string The filesystem path of the background image temp file 97 */ 98 public function getBackgroundImageTempfilePath() 99 { 100 return $this->getBackgroundImageDefaultFolder() . "background_upload.tmp"; 101 } 102 103 /** 104 * Returns the web path of the background image 105 * 106 * @return string The web path of the background image 107 */ 108 public function getBackgroundImagePathWeb() 109 { 110 include_once "./Services/Utilities/classes/class.ilUtil.php"; 111 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $this->getBackgroundImagePath()); 112 } 113 114 /** 115 * Returns the web path of the background image thumbnail 116 * 117 * @return string The web path of the background image thumbnail 118 */ 119 public function getBackgroundImageThumbPathWeb() 120 { 121 include_once "./Services/Utilities/classes/class.ilUtil.php"; 122 return str_replace(ilUtil::removeTrailingPathSeparators(ILIAS_ABSOLUTE_PATH), ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH), $this->getBackgroundImageThumbPath()); 123 } 124 125 /** 126 * Uploads a background image for the certificate. Creates a new directory for the 127 * certificate if needed. Removes an existing certificate image if necessary 128 * 129 * @param string $image_tempfilename Name of the temporary uploaded image file 130 * @return integer An errorcode if the image upload fails, 0 otherwise 131 */ 132 public function uploadBackgroundImage($image_tempfilename) 133 { 134 if (!empty($image_tempfilename)) { 135 $convert_filename = $this->getBackgroundImageName(); 136 $imagepath = $this->getBackgroundImageDefaultFolder(); 137 if (!file_exists($imagepath)) { 138 ilUtil::makeDirParents($imagepath); 139 } 140 // upload the file 141 if (!ilUtil::moveUploadedFile( 142 $image_tempfilename, 143 basename($this->getBackgroundImageTempfilePath()), 144 $this->getBackgroundImageTempfilePath() 145 )) { 146 return false; 147 } 148 // convert the uploaded file to JPEG 149 ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImagePath(), "JPEG"); 150 ilUtil::convertImage($this->getBackgroundImageTempfilePath(), $this->getBackgroundImageThumbPath(), "JPEG", 100); 151 if (!file_exists($this->getBackgroundImagePath())) { 152 // something went wrong converting the file. use the original file and hope, that PDF can work with it 153 if (!ilUtil::moveUploadedFile($this->getBackgroundImageTempfilePath(), $convert_filename, $this->getBackgroundImagePath())) { 154 return false; 155 } 156 } 157 unlink($this->getBackgroundImageTempfilePath()); 158 if (file_exists($this->getBackgroundImagePath()) && (filesize($this->getBackgroundImagePath()) > 0)) { 159 return true; 160 } 161 } 162 return false; 163 } 164 165 /** 166 * Deletes the background image of a certificate 167 * 168 * @return boolean TRUE if the process succeeds 169 */ 170 public function deleteBackgroundImage() 171 { 172 $result = true; 173 if (file_exists($this->getBackgroundImageThumbPath())) { 174 $result = $result & unlink($this->getBackgroundImageThumbPath()); 175 } 176 if (file_exists($this->getBackgroundImagePath())) { 177 $result = $result & unlink($this->getBackgroundImagePath()); 178 } 179 if (file_exists($this->getBackgroundImageTempfilePath())) { 180 $result = $result & unlink($this->getBackgroundImageTempfilePath()); 181 } 182 return $result; 183 } 184} // END class.ilObjCertificateSettings 185