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

Modules/WebResource/classes/class.ilParameterAppender.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 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 define("LINKS_USER_ID",1);
00025 define("LINKS_SESSION_ID",2);
00026 define("LINKS_LOGIN",3);
00027 
00028 // Errors
00029 define("LINKS_ERR_NO_NAME",1);
00030 define("LINKS_ERR_NO_VALUE",2);
00031 define("LINKS_ERR_NO_NAME_VALUE",3);
00032 
00041 class ilParameterAppender
00042 {
00043         var $webr_id = null;
00044         var $db = null;
00045 
00046         var $err = null;
00047 
00048 
00053         function ilParameterAppender($webr_id)
00054         {
00055                 global $ilDB;
00056 
00057                 $this->webr_id = $webr_id;
00058                 $this->db =& $ilDB;
00059         }
00060 
00061         function getErrorCode()
00062         {
00063                 return $this->err;
00064         }
00065 
00066         // SET GET
00067         function getObjId()
00068         {
00069                 return $this->webr_id;
00070         }
00071 
00072         function setName($a_name)
00073         {
00074                 $this->name = $a_name;
00075         }
00076         function getName()
00077         {
00078                 return $this->name;
00079         }
00080         function setValue($a_value)
00081         {
00082                 $this->value = $a_value;
00083         }
00084         function getValue()
00085         {
00086                 return $this->value;
00087         }
00088 
00089         function validate()
00090         {
00091                 if(!strlen($this->getName()) and !$this->getValue())
00092                 {
00093                         $this->err = LINKS_ERR_NO_NAME_VALUE;
00094                         return false;
00095                 }
00096                 if(!strlen($this->getName()))
00097                 {
00098                         $this->err = LINKS_ERR_NO_NAME;
00099                         return false;
00100                 }
00101                 if(!$this->getValue())
00102                 {
00103                         $this->err = LINKS_ERR_NO_VALUE;
00104                         return false;
00105                 }
00106                 return true;
00107         }
00108 
00109         
00110         function add($a_link_id)
00111         {
00112                 global $ilDB;
00113                 
00114                 if(!$a_link_id)
00115                 {
00116                         return false;
00117                 }
00118                 if(!strlen($this->getName() or !strlen($this->getValue())))
00119                 {
00120                         return false;
00121                 }
00122 
00123                 $query = "INSERT INTO webr_params ".
00124                         "SET webr_id = ".$ilDB->quote($this->getObjId()).", ".
00125                         "link_id = ".$ilDB->quote($a_link_id).", ".
00126                         "name = ".$ilDB->quote($this->getName()).", ".
00127                         "value = ".$ilDB->quote($this->getValue());
00128 
00129                 $this->db->query($query);
00130 
00131                 return $this->db->getLastInsertId();
00132         }
00133         
00134         function delete($a_param_id)
00135         {
00136                 global $ilDB;
00137                 
00138                 $this->db->query("DELETE FROM webr_params WHERE param_id = ".
00139                         $ilDB->quote((int) $a_param_id)." AND webr_id = ".$ilDB->quote($this->getObjId()));
00140 
00141                 return true;
00142         }
00143         
00144         // Static
00145         function _isEnabled()
00146         {
00147                 global $ilias;
00148 
00149                 return $ilias->getSetting('links_dynamic',false) ? true : false;
00150         }
00151 
00152         function &_append(&$a_link_data)
00153         {
00154                 global $ilUser;
00155 
00156                 if(!is_array($a_link_data))
00157                 {
00158                         return false;
00159                 }
00160                 if(count($params = ilParameterAppender::_getParams($a_link_data['link_id'])))
00161                 {
00162                         // Check for prefix
00163                         foreach($params as $param_data)
00164                         {
00165                                 if(!strpos($a_link_data['target'],'?'))
00166                                 {
00167                                         $a_link_data['target'] .= "?";
00168                                 }
00169                                 else
00170                                 {
00171                                         $a_link_data['target'] .= "&";
00172                                 }
00173                                 $a_link_data['target'] .= ($param_data['name']."=");
00174                                 switch($param_data['value'])
00175                                 {
00176                                         case LINKS_LOGIN:
00177                                                 $a_link_data['target'] .= (urlencode($ilUser->getLogin()));
00178                                                 break;
00179                                                 
00180                                         case LINKS_SESSION_ID:
00181                                                 $a_link_data['target'] .= (session_id());
00182                                                 break;
00183                                                 
00184                                         case LINKS_USER_ID:
00185                                                 $a_link_data['target'] .= ($ilUser->getId());
00186                                                 break;
00187                                 }
00188                         }
00189                 }
00190                 return $a_link_data;
00191         }
00192                 
00193         function _getParams($a_link_id)
00194         {
00195                 global $ilDB;
00196 
00197                 $res = $ilDB->query("SELECT * FROM webr_params WHERE link_id = ".
00198                         $ilDB->quote((int) $a_link_id));
00199                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00200                 {
00201                         $params[$row->param_id]['name'] = $row->name;
00202                         $params[$row->param_id]['value'] = $row->value;
00203                 }
00204 
00205                 return count($params) ? $params : array();
00206         }
00207 
00208         function _deleteAll($a_webr_id)
00209         {
00210                 global $ilDB;
00211 
00212                 $ilDB->query("DELETE FROM webr_params WHERE webr_id = ".
00213                         $ilDB->quote((int) $a_webr_id));
00214 
00215                 return true;
00216         }
00217 
00218         function _getOptionSelect()
00219         {
00220                 global $lng;
00221 
00222                 return array(0 => $lng->txt('links_select_one'),
00223                                          LINKS_USER_ID => $lng->txt('links_user_id'),
00224                                          LINKS_LOGIN => $lng->txt('links_user_name'),
00225                                          LINKS_SESSION_ID => $lng->txt('links_session_id'));
00226         }
00227 }
00228 ?>

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