00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00040
00041
00042
00043
00044
00045
00050
00051
00052
00053
00054
00058
00059
00060
00061
00062
00063
00067
00068
00069
00070
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00124 function updateObjectValue($a_obj_id,$a_column,$a_value)
00125 {
00126 global $ilias;
00127
00128 if (!isset($a_obj_id))
00129 {
00130 $message = "perm::updateObjectValue(): No obj_id given!";
00131 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00132 }
00133
00134 if (!isset($a_column))
00135 {
00136 $message = "perm::updateObjectValue(): No table column specified!";
00137 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00138 }
00139
00140 $q = "UPDATE object_data ".
00141 "SET ".$a_column."='".ilUtil::addSlashes($a_value)."',".
00142 "last_update=now() ".
00143 "WHERE obj_id='".$a_id."'";
00144 $ilias->db->query($q);
00145
00146 return true;
00147 }
00148
00155 function fetchObjectData($a_row)
00156 {
00157 $arr = array (
00158 "obj_id" => $a_row->obj_id,
00159 "ref_id" => $a_row->ref_id,
00160 "type" => $a_row->type,
00161 "title" => $a_row->title,
00162 "description" => $a_row->description,
00163 "desc" => $a_row->description,
00164 "usr_id" => $a_row->owner,
00165 "owner" => $a_row->owner,
00166 "create_date" => $a_row->create_date,
00167 "last_update" => $a_row->last_update,
00168 "last_login" => $a_row->last_login,
00169 "assign" => $a_row->assign,
00170 "protected" => $a_row->protected,
00171 "parent" => $a_row->parent
00172 );
00173
00174 return $arr ? $arr : array();
00175 }
00176
00177
00188 function getObjectList ($a_obj_type = "",$a_order = "", $a_direction = "ASC", $a_offset = "",$a_limit = "")
00189 {
00190 global $ilias;
00191
00192
00193 if (!$a_order)
00194 {
00195 $a_order = "title";
00196 }
00197
00198 $order = "ORDER BY ".$a_order." ".$a_direction;
00199
00200
00201 if ($a_limit && $a_offset)
00202 {
00203 $limit_clause = " LIMIT ".$a_offset.",".$a_limit;
00204 }
00205
00206
00207 if ($a_obj_type)
00208 {
00209 $where_clause = "WHERE type = '".$a_obj_type."' ";
00210 }
00211
00212 $q = "SELECT * FROM object_data ".$where_clause.$order.$limit_clause;
00213 $r = $ilias->db->query($q);
00214
00215 if ($r->numRows() > 0)
00216 {
00217 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00218 {
00219 $arr[$row->obj_id] = fetchObjectData($row);
00220 }
00221
00222 return $arr;
00223 }
00224
00225 return false;
00226 }
00227
00237 function getOperationList ($a_type = null)
00238 {
00239 global $ilias;
00240
00241 $arr = array();
00242
00243 if ($a_type)
00244 {
00245 $q = "SELECT * FROM rbac_operations ".
00246 "LEFT JOIN rbac_ta ON rbac_operations.ops_id = rbac_ta.ops_id ".
00247 "LEFT JOIN object_data ON rbac_ta.typ_id = object_data.obj_id ".
00248 "WHERE object_data.title='".$a_type."' AND object_data.type='typ' ".
00249 "ORDER BY 'order' ASC";
00250 }
00251 else
00252 {
00253 $q = "SELECT * FROM rbac_operations ".
00254 "ORDER BY 'order' ASC";
00255 }
00256
00257 $r = $ilias->db->query($q);
00258
00259 while ($row = $r->fetchRow())
00260 {
00261 $arr[] = array(
00262 "ops_id" => $row[0],
00263 "operation" => $row[1],
00264 "desc" => $row[2],
00265 "class" => $row[3],
00266 "order" => $row[4]
00267 );
00268 }
00269
00270 return $arr;
00271 }
00272
00273 function groupOperationsByClass($a_ops_arr)
00274 {
00275 $arr = array();
00276
00277 foreach ($a_ops_arr as $ops)
00278 {
00279 $arr[$ops['class']][] = array ('ops_id' => $ops['ops_id'],
00280 'name' => $ops['operation']
00281 );
00282 }
00283
00284 return $arr;
00285 }
00286
00294 function createNewOperation ($a_operation,$a_description)
00295 {
00296 global $ilias;
00297
00298 if (!isset($a_operation))
00299 {
00300 $message = "perm::createNewOperation(): No operation name given!";
00301 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00302 }
00303
00304
00305 $ops_id = getOperationId($a_operation);
00306
00307 if (!empty($ops_id))
00308 {
00309 $message = "perm::createNewOperation(): An operation '".$a_operation."' is already defined!";
00310 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00311 }
00312
00313 $q = "INSERT INTO operations ".
00314 "(operation,description) ".
00315 "VALUES ".
00316 "('".ilUtil::addSlashes($a_operation)."','".ilUtil::addSlashes($a_description)."')";
00317 $ilias->db->query($q);
00318
00319 return $ilias->db->getLastInsertId();
00320 }
00321
00328 function getOperationId($a_operation)
00329 {
00330 global $ilias;
00331
00332 if (!isset($a_operation))
00333 {
00334 $message = "perm::getOperationId(): No operation given!";
00335 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00336 }
00337
00338 $q = "SELECT DISTINCT ops_id FROM rbac_operations ".
00339 "WHERE operation ='".$a_operation."'";
00340 $row = $ilias->db->getRow($q);
00341
00342 return $row->ops_id;
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00371 function isUserLoggedIn ()
00372 {
00373 global $ilias;
00374
00375 $user_id = $ilias->account->getId();
00376
00377 if (empty($user_id))
00378 {
00379 return false;
00380 }
00381
00382 return true;
00383 }
00384
00392 function trimDeluxe ($a_text)
00393 {
00394 str_replace("\t"," ",$a_text);
00395
00396 for ($i=0;$i<50;$i++)
00397 {
00398 str_replace(" "," ",$a_text);
00399 }
00400
00401 $a_text = trim($a_text);
00402
00403 return $a_text;
00404 }
00405
00409
00410
00411
00412
00413
00422 function loginExists($a_login,$a_user_id = 0)
00423 {
00424 global $ilias;
00425
00426 if ($a_user_id == 0)
00427 {
00428 $clause = "";
00429 }
00430 else
00431 {
00432 $clause = "AND usr_id != '".$a_user_id."'";
00433 }
00434
00435 $q = "SELECT DISTINCT login FROM usr_data ".
00436 "WHERE login = '".ilUtil::stripSlashes($a_login)."' ".$clause;
00437 $r = $ilias->db->query($q);
00438
00439 if ($r->numRows() == 1)
00440 {
00441 return true;
00442 }
00443
00444 return false;
00445 }
00446
00455 function sendInfo($a_info = "",$a_keep = false)
00456 {
00457 global $tpl;
00458
00459 if (!empty($a_info))
00460 {
00461 $_SESSION["info"] = $a_info;
00462 }
00463 if (!empty($_SESSION["info"]))
00464 {
00465 $tpl->addBlockFile("MESSAGE", "message", "tpl.message.html");
00466 # $tpl->setCurrentBlock("message");
00467 $tpl->setVariable("INFO",$_SESSION["info"]);
00468 # $tpl->parseCurrentBlock();
00469 }
00470
00471 if (!$a_keep)
00472 {
00473 session_unregister("info");
00474 }
00475 }
00476
00477 function infoPanel($a_keep = true)
00478 {
00479 global $tpl,$ilias,$lng;
00480
00481 if (!empty($_SESSION["infopanel"]) and is_array($_SESSION["infopanel"]))
00482 {
00483 $tpl->addBlockFile("INFOPANEL", "infopanel", "tpl.infopanel.html");
00484 $tpl->setCurrentBlock("infopanel");
00485
00486 if (!empty($_SESSION["infopanel"]["text"]))
00487 {
00488 $link = "<a href=\"".$dir.$_SESSION["infopanel"]["link"]."\" target=\"".
00489 ilFrameTargetInfo::_getFrame("MainContent").
00490 "\">";
00491 $link .= $lng->txt($_SESSION["infopanel"]["text"]);
00492 $link .= "</a>";
00493 }
00494
00495
00496 if (!empty($_SESSION["infopanel"]["img"]))
00497 {
00498 $link .= "<td><a href=\"".$_SESSION["infopanel"]["link"]."\" target=\"".
00499 ilFrameTargetInfo::_getFrame("MainContent").
00500 "\">";
00501 $link .= "<img src=\"".$ilias->tplPath.$ilias->account->prefs["skin"]."/images/".
00502 $_SESSION["infopanel"]["img"]."\" border=\"0\" vspace=\"0\"/>";
00503 $link .= "</a></td>";
00504 }
00505
00506 $tpl->setVariable("INFO_ICONS",$link);
00507 $tpl->parseCurrentBlock();
00508 }
00509
00510
00511
00512 session_unregister("infopanel");
00513
00514 }
00515 ?>