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

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

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1