ILIAS  Release_3_10_x_branch Revision 61812
 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  function getObjId()
68  {
69  return $this->webr_id;
70  }
71 
72  function setName($a_name)
73  {
74  $this->name = $a_name;
75  }
76  function getName()
77  {
78  return $this->name;
79  }
80  function setValue($a_value)
81  {
82  $this->value = $a_value;
83  }
84  function getValue()
85  {
86  return $this->value;
87  }
88 
89  function validate()
90  {
91  if(!strlen($this->getName()) and !$this->getValue())
92  {
93  $this->err = LINKS_ERR_NO_NAME_VALUE;
94  return false;
95  }
96  if(!strlen($this->getName()))
97  {
98  $this->err = LINKS_ERR_NO_NAME;
99  return false;
100  }
101  if(!$this->getValue())
102  {
103  $this->err = LINKS_ERR_NO_VALUE;
104  return false;
105  }
106  return true;
107  }
108 
109 
110  function add($a_link_id)
111  {
112  global $ilDB;
113 
114  if(!$a_link_id)
115  {
116  return false;
117  }
118  if(!strlen($this->getName() or !strlen($this->getValue())))
119  {
120  return false;
121  }
122 
123  $query = "INSERT INTO webr_params ".
124  "SET webr_id = ".$ilDB->quote($this->getObjId()).", ".
125  "link_id = ".$ilDB->quote($a_link_id).", ".
126  "name = ".$ilDB->quote($this->getName()).", ".
127  "value = ".$ilDB->quote($this->getValue());
128 
129  $this->db->query($query);
130 
131  return $this->db->getLastInsertId();
132  }
133 
134  function delete($a_param_id)
135  {
136  global $ilDB;
137 
138  $this->db->query("DELETE FROM webr_params WHERE param_id = ".
139  $ilDB->quote((int) $a_param_id)." AND webr_id = ".$ilDB->quote($this->getObjId()));
140 
141  return true;
142  }
143 
144  // Static
145  function _isEnabled()
146  {
147  global $ilias;
148 
149  return $ilias->getSetting('links_dynamic',false) ? true : false;
150  }
151 
152  function &_append(&$a_link_data)
153  {
154  global $ilUser;
155 
156  if(!is_array($a_link_data))
157  {
158  return false;
159  }
160  if(count($params = ilParameterAppender::_getParams($a_link_data['link_id'])))
161  {
162  // Check for prefix
163  foreach($params as $param_data)
164  {
165  if(!strpos($a_link_data['target'],'?'))
166  {
167  $a_link_data['target'] .= "?";
168  }
169  else
170  {
171  $a_link_data['target'] .= "&";
172  }
173  $a_link_data['target'] .= ($param_data['name']."=");
174  switch($param_data['value'])
175  {
176  case LINKS_LOGIN:
177  $a_link_data['target'] .= (urlencode($ilUser->getLogin()));
178  break;
179 
180  case LINKS_SESSION_ID:
181  $a_link_data['target'] .= (session_id());
182  break;
183 
184  case LINKS_USER_ID:
185  $a_link_data['target'] .= ($ilUser->getId());
186  break;
187  }
188  }
189  }
190  return $a_link_data;
191  }
192 
193  function _getParams($a_link_id)
194  {
195  global $ilDB;
196 
197  $res = $ilDB->query("SELECT * FROM webr_params WHERE link_id = ".
198  $ilDB->quote((int) $a_link_id));
199  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
200  {
201  $params[$row->param_id]['name'] = $row->name;
202  $params[$row->param_id]['value'] = $row->value;
203  }
204 
205  return count($params) ? $params : array();
206  }
207 
208  function _deleteAll($a_webr_id)
209  {
210  global $ilDB;
211 
212  $ilDB->query("DELETE FROM webr_params WHERE webr_id = ".
213  $ilDB->quote((int) $a_webr_id));
214 
215  return true;
216  }
217 
218  function _getOptionSelect()
219  {
220  global $lng;
221 
222  return array(0 => $lng->txt('links_select_one'),
223  LINKS_USER_ID => $lng->txt('links_user_id'),
224  LINKS_LOGIN => $lng->txt('links_user_name'),
225  LINKS_SESSION_ID => $lng->txt('links_session_id'));
226  }
227 }
228 ?>