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
00071
00083 function updateObject ($a_obj_id,$a_title,$a_desc,$a_len_title=MAXLENGTH_OBJ_TITLE,$a_len_desc=MAXLENGTH_OBJ_DESC,$a_dots=true)
00084 {
00085 global $ilias;
00086
00087 if (!isset($a_obj_id))
00088 {
00089 $message = "perm::updateObject(): No obj_id given!";
00090 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00091 }
00092
00093 if (empty($a_title))
00094 {
00095 $message = "perm::updateObject(): No title given! A title is required!";
00096 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00097 }
00098
00099
00100 $a_title = ilUtil::shortenText($a_title,$a_len_title,$a_dots);
00101 $_desc = ilUtil::shortenText($a_desc,$a_len_desc,$a_dots);
00102
00103 $q = "UPDATE object_data ".
00104 "SET ".
00105 "title='".ilUtil::addSlashes($a_title)."',".
00106 "description='".ilUtil::addSlashes($a_desc)."', ".
00107 "last_update=now() ".
00108 "WHERE obj_id='".$a_obj_id."'";
00109 $ilias->db->query($q);
00110
00111 return true;
00112 }
00113
00122 function updateObjectValue($a_obj_id,$a_column,$a_value)
00123 {
00124 global $ilias;
00125
00126 if (!isset($a_obj_id))
00127 {
00128 $message = "perm::updateObjectValue(): No obj_id given!";
00129 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00130 }
00131
00132 if (!isset($a_column))
00133 {
00134 $message = "perm::updateObjectValue(): No table column specified!";
00135 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00136 }
00137
00138 $q = "UPDATE object_data ".
00139 "SET ".$a_column."='".ilUtil::addSlashes($a_value)."',".
00140 "last_update=now() ".
00141 "WHERE obj_id='".$a_id."'";
00142 $ilias->db->query($q);
00143
00144 return true;
00145 }
00146
00153 function fetchObjectData($a_row)
00154 {
00155 $arr = array (
00156 "obj_id" => $a_row->obj_id,
00157 "ref_id" => $a_row->ref_id,
00158 "type" => $a_row->type,
00159 "title" => ilUtil::stripSlashes($a_row->title),
00160 "description" => ilUtil::stripSlashes($a_row->description),
00161 "desc" => ilUtil::stripSlashes($a_row->description),
00162 "usr_id" => $a_row->owner,
00163 "owner" => $a_row->owner,
00164 "create_date" => $a_row->create_date,
00165 "last_update" => $a_row->last_update,
00166 "last_login" => $a_row->last_login,
00167 "assign" => $a_row->assign,
00168 "parent" => $a_row->parent
00169 );
00170
00171 return $arr ? $arr : array();
00172 }
00173
00174
00185 function getObjectList ($a_obj_type = "",$a_order = "", $a_direction = "ASC", $a_offset = "",$a_limit = "")
00186 {
00187 global $ilias;
00188
00189
00190 if (!$a_order)
00191 {
00192 $a_order = "title";
00193 }
00194
00195 $order = "ORDER BY ".$a_order." ".$a_direction;
00196
00197
00198 if ($a_limit && $a_offset)
00199 {
00200 $limit_clause = " LIMIT ".$a_offset.",".$a_limit;
00201 }
00202
00203
00204 if ($a_obj_type)
00205 {
00206 $where_clause = "WHERE type = '".$a_obj_type."' ";
00207 }
00208
00209 $q = "SELECT * FROM object_data ".$where_clause.$order.$limit_clause;
00210 $r = $ilias->db->query($q);
00211
00212 if ($r->numRows() > 0)
00213 {
00214 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
00215 {
00216 $arr[$row->obj_id] = fetchObjectData($row);
00217 }
00218
00219 return $arr;
00220 }
00221
00222 return false;
00223 }
00224
00234 function getOperationList ($a_type = "",$a_order= "",$a_direction = "")
00235 {
00236 global $ilias;
00237
00238 if (!$a_order)
00239 {
00240 $a_order = "operation";
00241 }
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 rbac_operations.".$a_order." ".$a_direction;
00250 }
00251 else
00252 {
00253 $q = "SELECT * FROM rbac_operations ".
00254 "ORDER BY ".$a_order." ".$a_direction;
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 );
00266 }
00267
00268 return $arr;
00269 }
00270
00278 function createNewOperation ($a_operation,$a_description)
00279 {
00280 global $ilias;
00281
00282 if (!isset($a_operation))
00283 {
00284 $message = "perm::createNewOperation(): No operation name given!";
00285 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00286 }
00287
00288
00289 $ops_id = getOperationId($a_operation);
00290
00291 if (!empty($ops_id))
00292 {
00293 $message = "perm::createNewOperation(): An operation '".$a_operation."' is already defined!";
00294 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00295 }
00296
00297 $q = "INSERT INTO operations ".
00298 "(operation,description) ".
00299 "VALUES ".
00300 "('".ilUtil::addSlashes($a_operation)."','".ilUtil::addSlashes($a_description)."')";
00301 $ilias->db->query($q);
00302
00303 return $ilias->db->getLastInsertId();
00304 }
00305
00312 function getOperationId($a_operation)
00313 {
00314 global $ilias;
00315
00316 if (!isset($a_operation))
00317 {
00318 $message = "perm::getOperationId(): No operation given!";
00319 $ilias->raiseError($message,$ilias->error_obj->WARNING);
00320 }
00321
00322 $q = "SELECT DISTINCT ops_id FROM rbac_operations ".
00323 "WHERE operation ='".$a_operation."'";
00324 $row = $ilias->db->getRow($q);
00325
00326 return $row->ops_id;
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00355 function isUserLoggedIn ()
00356 {
00357 global $ilias;
00358
00359 $user_id = $ilias->account->getId();
00360
00361 if (empty($user_id))
00362 {
00363 return false;
00364 }
00365
00366 return true;
00367 }
00368
00376 function trimDeluxe ($a_text)
00377 {
00378 str_replace("\t"," ",$a_text);
00379
00380 for ($i=0;$i<50;$i++)
00381 {
00382 str_replace(" "," ",$a_text);
00383 }
00384
00385 $a_text = trim($a_text);
00386
00387 return $a_text;
00388 }
00389
00393
00394
00395
00396
00397
00406 function loginExists($a_login,$a_user_id = 0)
00407 {
00408 global $ilias;
00409
00410 if ($a_user_id == 0)
00411 {
00412 $clause = "";
00413 }
00414 else
00415 {
00416 $clause = "AND usr_id != '".$a_user_id."'";
00417 }
00418
00419 $q = "SELECT DISTINCT login FROM usr_data ".
00420 "WHERE login = '".ilUtil::stripSlashes($a_login)."' ".$clause;
00421 $r = $ilias->db->query($q);
00422
00423 if ($r->numRows() == 1)
00424 {
00425 return true;
00426 }
00427
00428 return false;
00429 }
00430
00439 function sendInfo($a_info = "",$a_keep = false)
00440 {
00441 global $tpl;
00442
00443 if (!empty($a_info))
00444 {
00445 $_SESSION["info"] = $a_info;
00446 }
00447
00448 if (!empty($_SESSION["info"]))
00449 {
00450 $tpl->addBlockFile("MESSAGE", "message", "tpl.message.html");
00451 # $tpl->setCurrentBlock("message");
00452 $tpl->setVariable("INFO",$_SESSION["info"]);
00453 # $tpl->parseCurrentBlock();
00454 }
00455
00456 if (!$a_keep)
00457 {
00458 session_unregister("info");
00459 }
00460 }
00461
00462 function infoPanel($a_keep = true)
00463 {
00464 global $tpl,$ilias,$lng;
00465
00466 if (!empty($_SESSION["infopanel"]) and is_array($_SESSION["infopanel"]))
00467 {
00468 $tpl->addBlockFile("INFOPANEL", "infopanel", "tpl.infopanel.html");
00469 $tpl->setCurrentBlock("infopanel");
00470
00471 if (!empty($_SESSION["infopanel"]["text"]))
00472 {
00473 $link = "<a href=\"".$dir.$_SESSION["infopanel"]["link"]."\" target=\"bottom\">";
00474 $link .= $lng->txt($_SESSION["infopanel"]["text"]);
00475 $link .= "</a>";
00476 }
00477
00478
00479 if (!empty($_SESSION["infopanel"]["img"]))
00480 {
00481 $link .= "<td><a href=\"".$_SESSION["infopanel"]["link"]."\" target=\"bottom\">";
00482 $link .= "<img src=\"".$ilias->tplPath.$ilias->account->prefs["skin"]."/images/".
00483 $_SESSION["infopanel"]["img"]."\" border=\"0\" vspace=\"0\"/>";
00484 $link .= "</a></td>";
00485 }
00486
00487 $tpl->setVariable("INFO_ICONS",$link);
00488 $tpl->parseCurrentBlock();
00489 }
00490
00491
00492
00493 session_unregister("infopanel");
00494
00495 }
00496 ?>