ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilParameterAppender.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
24define("LINKS_USER_ID",1);
25define("LINKS_SESSION_ID",2);
26define("LINKS_LOGIN",3);
27define('LINKS_MATRICULATION',4);
28
29// Errors
30define("LINKS_ERR_NO_NAME",1);
31define("LINKS_ERR_NO_VALUE",2);
32define("LINKS_ERR_NO_NAME_VALUE",3);
33
43{
44 var $webr_id = null;
45 var $db = null;
46
47 var $err = null;
48
49
55 {
56 global $ilDB;
57
58 $this->webr_id = $webr_id;
59 $this->db =& $ilDB;
60 }
61
68 public static function getParameterIds($a_webr_id,$a_link_id)
69 {
70 global $ilDB;
71
72 $query = "SELECT * FROM webr_params ".
73 "WHERE webr_id = ".$ilDB->quote($a_webr_id,'integer')." ".
74 "AND link_id = ".$ilDB->quote($a_link_id,'integer');
75 $res = $ilDB->query($query);
76 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
77 {
78 $params[] = $row['param_id'];
79 }
80 return (array) $params;
81 }
82
83 function getErrorCode()
84 {
85 return $this->err;
86 }
87
88 // SET GET
89 public function setObjId($a_obj_id)
90 {
91 $this->webr_id = $a_obj_id;
92 }
93
94 function getObjId()
95 {
96 return $this->webr_id;
97 }
98
99 function setName($a_name)
100 {
101 $this->name = $a_name;
102 }
103 function getName()
104 {
105 return $this->name;
106 }
107 function setValue($a_value)
108 {
109 $this->value = $a_value;
110 }
111 function getValue()
112 {
113 return $this->value;
114 }
115
116 function validate()
117 {
118 if(!strlen($this->getName()) and !$this->getValue())
119 {
120 $this->err = LINKS_ERR_NO_NAME_VALUE;
121 return false;
122 }
123 if(!strlen($this->getName()))
124 {
125 $this->err = LINKS_ERR_NO_NAME;
126 return false;
127 }
128 if(!$this->getValue())
129 {
130 $this->err = LINKS_ERR_NO_VALUE;
131 return false;
132 }
133 return true;
134 }
135
136
137 function add($a_link_id)
138 {
139 global $ilDB;
140
141 if(!$a_link_id)
142 {
143 return false;
144 }
145 if(!strlen($this->getName() or !strlen($this->getValue())))
146 {
147 return false;
148 }
149
150 $next_id = $ilDB->nextId('webr_params');
151 $query = "INSERT INTO webr_params (param_id,webr_id,link_id,name,value) ".
152 "VALUES( ".
153 $ilDB->quote($next_id,'integer').", ".
154 $ilDB->quote($this->getObjId() ,'integer').", ".
155 $ilDB->quote($a_link_id ,'integer').", ".
156 $ilDB->quote($this->getName() ,'text').", ".
157 $ilDB->quote($this->getValue() ,'integer').
158 ")";
159 $res = $ilDB->manipulate($query);
160
161 return $next_id;
162 }
163
164 function delete($a_param_id)
165 {
166 global $ilDB;
167
168 $query = "DELETE FROM webr_params ".
169 "WHERE param_id = ".$ilDB->quote($a_param_id ,'integer')." ".
170 "AND webr_id = ".$ilDB->quote($this->getObjId(),'integer');
171 $res = $ilDB->manipulate($query);
172 return true;
173 }
174
179 public static function _isEnabled()
180 {
181 global $ilSetting;
182
183 return $ilSetting->get('links_dynamic',false) ? true : false;
184 }
185
186 public static function _append($a_link_data)
187 {
188 global $ilUser;
189
190 if(!is_array($a_link_data))
191 {
192 return false;
193 }
194 if(count($params = ilParameterAppender::_getParams($a_link_data['link_id'])))
195 {
196 // Check for prefix
197 foreach($params as $param_data)
198 {
199 if(!strpos($a_link_data['target'],'?'))
200 {
201 $a_link_data['target'] .= "?";
202 }
203 else
204 {
205 $a_link_data['target'] .= "&";
206 }
207 $a_link_data['target'] .= ($param_data['name']."=");
208 switch($param_data['value'])
209 {
210 case LINKS_LOGIN:
211 $a_link_data['target'] .= (urlencode($ilUser->getLogin()));
212 break;
213
214 case LINKS_SESSION_ID:
215 $a_link_data['target'] .= (session_id());
216 break;
217
218 case LINKS_USER_ID:
219 $a_link_data['target'] .= ($ilUser->getId());
220 break;
221
223 $a_link_data['target'] .= ($ilUser->getMatriculation());
224 break;
225 }
226 }
227 }
228 return $a_link_data;
229 }
230
236 public static function _getParams($a_link_id)
237 {
238 global $ilDB;
239
240 $res = $ilDB->query("SELECT * FROM webr_params WHERE link_id = ".
241 $ilDB->quote((int) $a_link_id ,'integer'));
242 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
243 {
244 $params[$row->param_id]['name'] = $row->name;
245 $params[$row->param_id]['value'] = $row->value;
246 }
247
248 return count($params) ? $params : array();
249 }
250
257 public static function parameterToInfo($a_name,$a_value)
258 {
259 $info = $a_name;
260
261 switch($a_value)
262 {
263 case LINKS_USER_ID:
264 return $info.'=USER_ID';
265
266 case LINKS_SESSION_ID:
267 return $info.'=SESSION_ID';
268
269 case LINKS_LOGIN:
270 return $info.'=LOGIN';
271
273 return $info.'=MATRICULATION';
274 }
275 return '';
276 }
277
278 function _deleteAll($a_webr_id)
279 {
280 global $ilDB;
281
282 $query = "DELETE FROM webr_params WHERE webr_id = ".
283 $ilDB->quote((int) $a_webr_id ,'integer');
284 $res = $ilDB->manipulate($query);
285
286 return true;
287 }
288
293 public static function _getOptionSelect()
294 {
295 global $lng;
296
297 return array(0 => $lng->txt('links_select_one'),
298 LINKS_USER_ID => $lng->txt('links_user_id'),
299 LINKS_LOGIN => $lng->txt('links_user_name'),
300 LINKS_SESSION_ID => $lng->txt('links_session_id'),
301 LINKS_MATRICULATION => $lng->txt('matriculation')
302 );
303 }
304}
305?>
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
const LINKS_SESSION_ID
const LINKS_USER_ID
const LINKS_ERR_NO_NAME
const LINKS_LOGIN
const LINKS_MATRICULATION
const LINKS_ERR_NO_VALUE
const LINKS_ERR_NO_NAME_VALUE
Class ilParameterAppender.
static getParameterIds($a_webr_id, $a_link_id)
Get Parameter ids of link.
static parameterToInfo($a_name, $a_value)
Get info text describing an existing dynamic link.
static _append($a_link_data)
ilParameterAppender($webr_id)
Constructor @access public.
static _getOptionSelect()
Get options as array.
static _getParams($a_link_id)
Get dynamic parameter definitions.
static _isEnabled()
Check if dynamic parameters are enabled.
$params
Definition: example_049.php:96
$info
Definition: example_052.php:80
global $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15