ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 define("LINKS_USER_ID",1);
25 define("LINKS_SESSION_ID",2);
26 define("LINKS_LOGIN",3);
27 
28 // Errors
29 define("LINKS_ERR_NO_NAME",1);
30 define("LINKS_ERR_NO_VALUE",2);
31 define("LINKS_ERR_NO_NAME_VALUE",3);
32 
42 {
43  var $webr_id = null;
44  var $db = null;
45 
46  var $err = null;
47 
48 
54  {
55  global $ilDB;
56 
57  $this->webr_id = $webr_id;
58  $this->db =& $ilDB;
59  }
60 
61  function getErrorCode()
62  {
63  return $this->err;
64  }
65 
66  // SET GET
67  public function setObjId($a_obj_id)
68  {
69  $this->webr_id = $a_obj_id;
70  }
71 
72  function getObjId()
73  {
74  return $this->webr_id;
75  }
76 
77  function setName($a_name)
78  {
79  $this->name = $a_name;
80  }
81  function getName()
82  {
83  return $this->name;
84  }
85  function setValue($a_value)
86  {
87  $this->value = $a_value;
88  }
89  function getValue()
90  {
91  return $this->value;
92  }
93 
94  function validate()
95  {
96  if(!strlen($this->getName()) and !$this->getValue())
97  {
98  $this->err = LINKS_ERR_NO_NAME_VALUE;
99  return false;
100  }
101  if(!strlen($this->getName()))
102  {
103  $this->err = LINKS_ERR_NO_NAME;
104  return false;
105  }
106  if(!$this->getValue())
107  {
108  $this->err = LINKS_ERR_NO_VALUE;
109  return false;
110  }
111  return true;
112  }
113 
114 
115  function add($a_link_id)
116  {
117  global $ilDB;
118 
119  if(!$a_link_id)
120  {
121  return false;
122  }
123  if(!strlen($this->getName() or !strlen($this->getValue())))
124  {
125  return false;
126  }
127 
128  $next_id = $ilDB->nextId('webr_params');
129  $query = "INSERT INTO webr_params (param_id,webr_id,link_id,name,value) ".
130  "VALUES( ".
131  $ilDB->quote($next_id,'integer').", ".
132  $ilDB->quote($this->getObjId() ,'integer').", ".
133  $ilDB->quote($a_link_id ,'integer').", ".
134  $ilDB->quote($this->getName() ,'text').", ".
135  $ilDB->quote($this->getValue() ,'integer').
136  ")";
137  $res = $ilDB->manipulate($query);
138 
139  return $next_id;
140  }
141 
142  function delete($a_param_id)
143  {
144  global $ilDB;
145 
146  $query = "DELETE FROM webr_params ".
147  "WHERE param_id = ".$ilDB->quote($a_param_id ,'integer')." ".
148  "AND webr_id = ".$ilDB->quote($this->getObjId(),'integer');
149  $res = $ilDB->manipulate($query);
150  return true;
151  }
152 
157  public static function _isEnabled()
158  {
159  global $ilSetting;
160 
161  return $ilSetting->get('links_dynamic',false) ? true : false;
162  }
163 
164  public static function _append($a_link_data)
165  {
166  global $ilUser;
167 
168  if(!is_array($a_link_data))
169  {
170  return false;
171  }
172  if(count($params = ilParameterAppender::_getParams($a_link_data['link_id'])))
173  {
174  // Check for prefix
175  foreach($params as $param_data)
176  {
177  if(!strpos($a_link_data['target'],'?'))
178  {
179  $a_link_data['target'] .= "?";
180  }
181  else
182  {
183  $a_link_data['target'] .= "&";
184  }
185  $a_link_data['target'] .= ($param_data['name']."=");
186  switch($param_data['value'])
187  {
188  case LINKS_LOGIN:
189  $a_link_data['target'] .= (urlencode($ilUser->getLogin()));
190  break;
191 
192  case LINKS_SESSION_ID:
193  $a_link_data['target'] .= (session_id());
194  break;
195 
196  case LINKS_USER_ID:
197  $a_link_data['target'] .= ($ilUser->getId());
198  break;
199  }
200  }
201  }
202  return $a_link_data;
203  }
204 
210  public static function _getParams($a_link_id)
211  {
212  global $ilDB;
213 
214  $res = $ilDB->query("SELECT * FROM webr_params WHERE link_id = ".
215  $ilDB->quote((int) $a_link_id ,'integer'));
216  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
217  {
218  $params[$row->param_id]['name'] = $row->name;
219  $params[$row->param_id]['value'] = $row->value;
220  }
221 
222  return count($params) ? $params : array();
223  }
224 
231  public static function parameterToInfo($a_name,$a_value)
232  {
233  $info = $a_name;
234 
235  switch($a_value)
236  {
237  case LINKS_USER_ID:
238  return $info.'=USER_ID';
239 
240  case LINKS_SESSION_ID:
241  return $info.'=SESSION_ID';
242 
243  case LINKS_LOGIN:
244  return $info.'=LOGIN';
245  }
246  return '';
247  }
248 
249  function _deleteAll($a_webr_id)
250  {
251  global $ilDB;
252 
253  $query = "DELETE FROM webr_params WHERE webr_id = ".
254  $ilDB->quote((int) $a_webr_id ,'integer');
255  $res = $ilDB->manipulate($query);
256 
257  return true;
258  }
259 
264  public static function _getOptionSelect()
265  {
266  global $lng;
267 
268  return array(0 => $lng->txt('links_select_one'),
269  LINKS_USER_ID => $lng->txt('links_user_id'),
270  LINKS_LOGIN => $lng->txt('links_user_name'),
271  LINKS_SESSION_ID => $lng->txt('links_session_id'));
272  }
273 }
274 ?>